有人知道matlab中repmat函数和cell创建元包数组,在python中用什么实现么,急!!! !
1、repmat()函数用python怎么实现
2、cell()函数用python怎么实现
import numpy as np A=np.matrix([[1,2],[3,4]]) A = repmat(A,2,3) print(A)
结果:
[[1. 2. 1. 2. 1. 2.] [3. 4. 3. 4. 3. 4.] [1. 2. 1. 2. 1. 2.] [3. 4. 3. 4. 3. 4.]]
2.cell
直接用[] 创建就行。例如:
A=["33",2,[2,2],[99.0,'test',[]]]
得到的是:
>>> print(A)
['33', 2, [2, 2], [99.0, 'test', []]]
1.repmat
def repmat(A,a,b): ncol = A.shape[0] nrow = A.shape[1] B=np.zeros([ncol*a, nrow*b]) for i in range(0,ncol*a): for j in range(0,nrow*b): B[i,j] = A[i%ncol, j%nrow] return B
调用如下: