Zuerst erstelle ich die 2x3 Liste und dann weise ich jedem Listenelement ein 4x8 Array zu.
Zur Verifikation nummeriere ich jeden Zeilenvektor vom Array mit einem laufenden Zähler.
Insgesamt sind das 2x3x4=24 Array-Achsen, bzw. Vektoren.
Das funktioniert so wie unten angeschrieben, aber sind doch recht viele for-Schleifen.
Gibt es eine bessere/effizientere/übersichtlichere Möglichkeit dies zu tun ?
Vor allem die Zusweisung der Arrays an jedes einzelne Listenelement kann doch bestimmt auch in einem Einzeiler formuliert werden, oder ?
Code: Alles auswählen
import numpy as np
#create a 2x3 list: 5 columns, 3 rows
list_row = 2
list_col = 3
mylist = [ [0 for j in range(list_col)] for i in range (list_row) ]
#numpy array dimensions
arry_row = 4
arry_col = 8
#assign an 2x8 numpy array to each element of the list
for i in range(list_row): #row index
for j in range(list_col): #columns index
mylist[i][j] = np.zeros((arry_row,arry_col)) #create a 2x8 numpy array filled with 0s
#then fill each numpy array-element with its row index
for i in range(list_row): #row list-index
for j in range(list_col): #column list-index
for k in range(arry_row): #each column
array_column = int( k + j*arry_row + i*list_col*arry_row ) #running column of array element
for l in range(arry_col): #assign to each of the array elements its corresponsing array-row-index
(mylist[i][j])[k][l] = array_column
print(mylist)
Code: Alles auswählen
[[array([[0., 0., 0., 0., 0., 0., 0., 0.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[2., 2., 2., 2., 2., 2., 2., 2.],
[3., 3., 3., 3., 3., 3., 3., 3.]]), array([[4., 4., 4., 4., 4., 4., 4., 4.],
[5., 5., 5., 5., 5., 5., 5., 5.],
[6., 6., 6., 6., 6., 6., 6., 6.],
[7., 7., 7., 7., 7., 7., 7., 7.]]), array([[ 8., 8., 8., 8., 8., 8., 8., 8.],
[ 9., 9., 9., 9., 9., 9., 9., 9.],
[10., 10., 10., 10., 10., 10., 10., 10.],
[11., 11., 11., 11., 11., 11., 11., 11.]])], [array([[12., 12., 12., 12., 12., 12., 12., 12.],
[13., 13., 13., 13., 13., 13., 13., 13.],
[14., 14., 14., 14., 14., 14., 14., 14.],
[15., 15., 15., 15., 15., 15., 15., 15.]]), array([[16., 16., 16., 16., 16., 16., 16., 16.],
[17., 17., 17., 17., 17., 17., 17., 17.],
[18., 18., 18., 18., 18., 18., 18., 18.],
[19., 19., 19., 19., 19., 19., 19., 19.]]), array([[20., 20., 20., 20., 20., 20., 20., 20.],
[21., 21., 21., 21., 21., 21., 21., 21.],
[22., 22., 22., 22., 22., 22., 22., 22.],
[23., 23., 23., 23., 23., 23., 23., 23.]])]]