简体   繁体   English

Python-复制到设置大小的Numpy数组中

[英]Python - Copying into Numpy Array of set size

I have an array of unknown size - below 100 x 100 in it's dimensions; 我有一个未知尺寸的数组-尺寸小于100 x 100; and I need to copy it into another Numpy array of a set size - 100 x 100. 我需要将其复制到另一个大小为100 x 100的Numpy数组中。

emptyArray = np.empty(shape=[100,100])
fullArray = np.append(emptyArray, data1[y1:y2, x1:x2])

I need this so I can work with fullArray's of the same size later on in my code but this does not seem to be working. 我需要这样做,以便以后可以在代码中使用相同大小的fullArray,但这似乎无法正常工作。 So the data would need to be appended into the top corner of the 100 x 100 array. 因此,需要将数据附加到100 x 100阵列的顶角。

Does anyone have any advice on a how to do this? 有人对如何执行此操作有任何建议吗? Be that an existing Numpy method or otherwise? 那是现有的Numpy方法还是其他?

You should know the dimension of your smaller array but I presume from your question that it is smaller than 100x100 but varies from simulation to simulation. 您应该知道较小数组的维数,但是我想从您的问题中猜出它小于100x100,但因仿真而异。 You can solve this like this: 您可以这样解决:

nx,ny = smallerArray.shape
largeArray[0:nx,0:ny] = smallerArray[0:nx,0:ny]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM