Python 使用另一个数组中的一些元素从另一个数组中创建一个数组,并填充零个其他元素
我有一个数组Python 使用另一个数组中的一些元素从另一个数组中创建一个数组,并填充零个其他元素,python,numpy,Python,Numpy,我有一个数组 np.random.seed(42) x = np.random.rand(3, 3) 所以 我想从这个数组中创建另一个元素,只使用x中的一些元素,并填充零个其他元素,例如,如果我想要元素x[1::2,::2]我将得到一个数组 y = np.array([[0, 0, 0], [0.59865848, 0, 0.15599452], [0, 0, 0]]) out=np.类零(x);out[1::2,::2]=x[1::2,:
np.random.seed(42)
x = np.random.rand(3, 3)
所以
我想从这个数组中创建另一个元素,只使用x中的一些元素,并填充零个其他元素,例如,如果我想要元素x[1::2,::2]
我将得到一个数组
y = np.array([[0, 0, 0],
[0.59865848, 0, 0.15599452],
[0, 0, 0]])
out=np.类零(x);out[1::2,::2]=x[1::2,::2]
@user3483203谢谢!它起作用了!
y = np.array([[0, 0, 0],
[0.59865848, 0, 0.15599452],
[0, 0, 0]])