![]() |
在NumPy中相当于MATLAB的repmat
我想使用NumPy执行以下MATLAB代码的等效项: repmat([1; 1], [1 1 1]) 。我将如何完成?
回答: [URL="https://docs.scipy.org/doc/numpy-1.15.0/user/numpy-for-matlab-users.html"]对于Matlab用户,[/URL]这里有一个更好(官方)的[URL="https://docs.scipy.org/doc/numpy-1.15.0/user/numpy-for-matlab-users.html"]NumPy[/URL]链接-恐怕其中的Mathesaurus已经过时了。 repmat(a, m, n)的numpy等价于[URL="http://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html"]tile(a, (m, n))[/URL] 。 这适用于多个维度,并提供与matlab类似的结果。 (Numpy给出了3d输出数组,正如您期望的那样-由于某些原因,matlab提供了2d输出-但内容相同)。 Matlab: >> repmat([1;1],[1,1,1]) ans = 1 1 蟒蛇: In [46]: a = np.array([[1],[1]]) In [47]: np.tile(a, [1,1,1]) Out[47]: array([[[1], [1]]]) [url=https://stackoverflow.com/questions/1721802]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 10:28。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.