从Matlab转换为repmat的python [英] conversion from matlab to python of repmat
本文介绍了从Matlab转换为repmat的python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将给定的matlab代码转换为python
I want to convert the given matlab code to python
img_o = repmat(fill_value, osize);
这里fill_value是一个1x1x3
矩阵和osize=[320 320]
输出矩阵为320x320x3
here fill_value is a 1x1x3
matrix and osize=[320 320]
output matrix is 320x320x3
我尝试过
img_o = tile(fill_value, osize)
其中
fill_value = numpy.array([[[0, 0, 0]]])
osize=[320,320]
在这里,我得到的是1x320x960
而不是320x320x3 matrix
的矩阵
请帮助解决
here i am getting a matrix of 1x320x960
instead of 320x320x3 matrix
please help to solve
推荐答案
Numpy进行了一些非直觉的工作,它们被非直觉地称为广播".这就是您需要的(只是尺寸向量上的一个更明确的维度):
Numpy does some nonintuitive stuff that it nonintuitively calls "broadcasting". Here's what you need (just one more explicit dimension on your size vector):
>>> osize = (320, 320, 1)
>>> img_o = numpy.tile(fill_value, osize)
>>> img_o.shape
(320, 320, 3)
这篇关于从Matlab转换为repmat的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文