0

我有两个不同形状的数组,例如:

a = np.zeros((2, 4))
b = np.ones((2, 3))

我想对它们执行以下操作:

x1, x2 = a.shape
b[:x1, :x2] = a[:x1, :x2] 

a我想通过在和之间翻转形状并b让它仍然工作的能力来实现这一点,即

a = np.zeros((2, 3)) # Note that I flipped 
b = np.ones((2, 4))  # the shapes from the previous example

x1, x2 = a.shape
b[:x1, :x2] = a[:x1, :x2]

可以使用本机 NumPy 并且不使用 for 循环来完成吗?

4

1 回答 1

0

找到我的解决方案:

x3, x4 = b.shape
b[:x1, :x2] = a[:x3, :x4]

为我做了伎俩。

于 2020-08-03T11:22:54.543 回答