python 基质处理[重复]

bvuwiixz  于 2023-01-19  发布在  Python
关注(0)|答案(1)|浏览(77)
    • 此问题在此处已有答案**:

Replace sub part of matrix by another small matrix in numpy(5个答案)
5小时前关门了。
我有一个大小为(3x2)的数组。我想把这些数组值插入到4x3的零数组中。我怎样在python中实现它呢?

import numpy as np

a = np.zeros((4,3))
b = np.ones((3, 2))
for i in range(4):
    for j in range(3):
        a[i,j] = b[i, j]
rmbxnbpk

rmbxnbpk1#

if len(x) < len(y):
    z = x.copy()
    z[:len(x)] += x
else:
    z = x.copy()
    z[:len(y)] += y

相关问题