Notes for yourself
Suppose you generate a list that has a 3x3 zero matrix as each element of the list as shown below.
A=[np.zeros((3,3))]*(3)
Consider assigning a value to this list
In : A Out: [array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]])]
Here, substitute the value in the first row of the first element (zero matrix) as shown below.
A[0][0]=1
After performing this operation, A becomes as follows.
In : A Out: [array([[ 1., 1., 1.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 1., 1., 1.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 1., 1., 1.], [ 0., 0., 0.], [ 0., 0., 0.]])]
Assigned to all elements! ??
Let's be careful……
(Gentlely ``` np.zeros ((3,3,3)) I wonder if it should have been generated with` ``
How smart is it when you want to create a multidimensional matrix with different numbers of elements for each element (I don't know if this kind of expression is allowed).
Recommended Posts