2024-03-28 09:20:56 发布
网友
在我的代码中,有一个矩阵是动态增加大小。Matlab中的伪代码如下:
cnt = 0 for ii = 1:M for jj = 1:N if (condition satisfied) cnt = cnt + 1 A(cnt, :, :) = I # I is a matrix that is created within the loop end end end
如何使用NumPy在Python中实现这一点?你知道吗
import numpy as np A = list() for i in range(M): for j in range(N): if condition satisfied: A.append(I) # I is a ndarray created within the loop. A = np.array(A)
相关问题 更多 >
编程相关推荐