在NumPy中相当于MATLAB的repmat [英] What is the equivalent of MATLAB's repmat in NumPy

查看:151
本文介绍了在NumPy中相当于MATLAB的repmat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用NumPy执行以下MATLAB代码的等效项:repmat([1; 1], [1 1 1]).我该怎么办?

I would like to execute the equivalent of the following MATLAB code using NumPy: repmat([1; 1], [1 1 1]). How would I accomplish this?

推荐答案

这是一个更好的(官方)

Here is a much better (official) NumPy for Matlab Users link - I'm afraid the mathesaurus one is quite out of date.

repmat(a, m, n)的numpy等效项是 tile(a, (m, n)) .

The numpy equivalent of repmat(a, m, n) is tile(a, (m, n)).

这适用于多个维度,并提供与matlab类似的结果. (Numpy会提供您期望的3d输出数组-由于某种原因,matlab会提供2d输出-但内容是相同的.)

This works with multiple dimensions and gives a similar result to matlab. (Numpy gives a 3d output array as you would expect - matlab for some reason gives 2d output - but the content is the same).

Matlab:

>> repmat([1;1],[1,1,1])

ans =
     1
     1

Python:

In [46]: a = np.array([[1],[1]])
In [47]: np.tile(a, [1,1,1])
Out[47]: 
array([[[1],
        [1]]])

这篇关于在NumPy中相当于MATLAB的repmat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆