M = np.zeros((N,L))
上面的语句给出了一个 N x L 矩阵,该矩阵最初填充了0。我需要类似的语句来创建 N x L 矩阵,其中填充了(0,0)
个元组。如何创建它?
答案 0 :(得分:0)
这个solution怎么样:
N = 3
L = 3
M = np.zeros((N,L))
res = np.array(list(zip(M.ravel(),M.ravel())), dtype=('i4,i4')).reshape(M.shape)
# returns
array([[(0, 0), (0, 0), (0, 0)],
[(0, 0), (0, 0), (0, 0)],
[(0, 0), (0, 0), (0, 0)]], dtype=[('f0', '<i4'), ('f1', '<i4')])