The dimensions of P
is (2,3,3)
. But the dimensions of M
is (3,3)
. How can I ensure that both P
and M
have the same dimensions i.e. (2,3,3)
.
import numpy as np
P=np.array([[[128.22918457, 168.52413295, 209.72343319],
[129.01598287, 179.03716051, 150.68633749],
[131.00688309, 187.42601593, 193.68172751]],
[[ 64.11459228, 84.26206648, 104.86171659],
[ 64.50799144, 89.51858026, 75.34316875],
[ 65.50344155, 93.71300796, 96.84086375]]])
for x in range(0,2):
M=P[x] 1
print(M)
CodePudding user response:
Just do
M = P 1
and that ensures M
and P
have the same dimensions.
CodePudding user response:
I don't know why you need this and for what (why you have tried to use M = P 1
for making the shape equal?). But, you can ensure they have same shapes using assert
:
assert a.shape == b.shape
It will get error when the shapes are not the same, so you can be sure that dimensions are the same if it didn't stuck and get error.