KLeine Matrix in Große Matrix schreiben
Verfasst: Freitag 22. August 2014, 14:50
Ich habe mich jetzt enige Zeit mit Matrizen in Numpy beschäftigt. Viele sachen bekomme ich hin und wie ich einen Wert an eine Stelle eines Arrays schreibe, hab ich auch verstanden, denke ich. Nun möchte ich aber eine kleine Matrix B in eine große Matrix A schreiben. Und zwar an eine beliebige Position.
Wie kann man die kleine Matrix B an eine beliebige Stelle der großen Matrix A schreiben, so dass man etwas erhält wie z.B.:
Bietet numpy da eine zwei-Zeilen-Lösung, die ich nicht gefunden habe?
Danke für eure Antworten
Code: Alles auswählen
>>>import numpy as np
>>>A= np.zeros([10,10])
array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
>>>B= np.ones([4,4])
array([[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]])
Code: Alles auswählen
C= array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 1., 1., 1., 1., 0., 0., 0.],
[ 0., 0., 0., 1., 1., 1., 1., 0., 0., 0.],
[ 0., 0., 0., 1., 1., 1., 1., 0., 0., 0.],
[ 0., 0., 0., 1., 1., 1., 1., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
Danke für eure Antworten