...最好直接显示代码。这里是:
import numpy as np
a = np.zeros([3, 3])
a
array([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
b = np.random.random_integers(0, 100, size = (1, 3))
b
array([[ 10, 3, 8]])
c = np.random.random_integers(0, 100, size = (4, 3))
c
array([[ 22, 21, 14],
[ 55, 64, 12],
[ 33, 85, 98],
[ 37, 44, 45]])
a = b will change dimensions of a
a = c will change dimensions of a
对于 a = b,我想要:
array([[ 10., 3., 8.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
对于 a = c,我想要:
array([[ 22, 21, 14],
[ 55, 64, 12],
[ 33, 85, 98]])
所以我想锁定“a”的形状,以便在必要时“裁剪”分配给它的值。当然没有 if 语句。