python - Slicing a 2D array to match entries from a 3D array? -
my task today slice 2d array matches correctly entries in 3d array. example, have 3d array below:
[[[ 1.06103295e+02 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.06103295e+02 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.06103295e+02]] [[ 5.09297818e+05 5.09296818e+05 5.09296818e+05] [ 5.09296818e+05 5.09297818e+05 5.09296818e+05] [ 5.09296818e+05 5.09296818e+05 5.09297818e+05]] [[ 5.09297818e+05 5.09296818e+05 5.09296818e+05] [ 5.09296818e+05 5.09297818e+05 5.09296818e+05] [ 5.09296818e+05 5.09296818e+05 5.09297818e+05]] [[ 1.06103295e+02 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.06103295e+02 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.06103295e+02]]]
using "numpy.reshape" command, changed 2d array dimensions (12, 3).
[[ 1.06103295e+02 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.06103295e+02 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.06103295e+02] [ 5.09297818e+05 5.09296818e+05 5.09296818e+05] [ 5.09296818e+05 5.09297818e+05 5.09296818e+05] [ 5.09296818e+05 5.09296818e+05 5.09297818e+05] [ 5.09297818e+05 5.09296818e+05 5.09296818e+05] [ 5.09296818e+05 5.09297818e+05 5.09296818e+05] [ 5.09296818e+05 5.09296818e+05 5.09297818e+05] [ 1.06103295e+02 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.06103295e+02 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.06103295e+02]]
now how slice entries in same form above?
for example, sliced 1 of entries such:
m11 = myarrayname[0:3, 0:3]
and got result:
[[ 106.10329539 0. 0. ] [ 0. 106.10329539 0. ] [ 0. 0. 106.10329539]]
notice same 1 of blocks 3d array above (minus scientific notation). how keep slicing entries other 3 blocks 3d array above?
when tried m12 = myarrayname[4:6, 4:6],
i got empty array.
you use np.reshape again (if a
array):
b = np.reshape(a, (12, 3)) c = np.reshape(b, (4, 3, 3))
but if you'd rather select arrays yourself, then:
m11 = b[0:3, 0:3] m12 = b[3:6, 0:3] m13 = b[6:9, 0:3] m14 = b[9:12, 0:3]
Comments
Post a Comment