调整大小或调整大小 [英] Numpy resize or Numpy reshape

查看:65
本文介绍了调整大小或调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找stackexchange档案,似乎无法找到正确的答案...应该使用重塑形状,应该使用重塑尺寸,但是都失败了...

I've been scouring the stackexchange archives and can not seem to come across the right answer... should reshape be used, should resize be used, but both fail...

设置:3个具有两种分辨率的netCDF文件... 1500米,2 1000米

setup: 3 netCDF files of two resolutions... 1 500 meter, 2 1000 meter

需要调整大小或降低分辨率或调整形状或其他适当的设置word是高分辨率文件:)

need to resize or decrease resolution or reshape or whatever the right word is the higher resolution file :)

使用gdalinfo或 print(np.shape(array)),我们知道高分辨率文件的形状或大小(2907,2331)和较低分辨率数组的大小为(1453,1166)

using either gdalinfo or "print (np.shape(array))" we know that the higher resolution file has a shape or size of (2907, 2331) and the lower resolution array has the size of (1453, 1166)

所以我尝试了两个np.resize(array,(1453,1166 ))和np.reshape(array,(1453,1166))并收到诸如以下错误:

So i have tried both np.resize (array, (1453,1166)) and np.reshape (array, (1453,1166)) and receive errors such as:

ValueError:无法将大小为6776217的数组重塑为形状(1453,1166) )

ValueError: cannot reshape array of size 6776217 into shape (1453,1166)

我肯定使用了错误的术语/行话,为此我道歉...在命令行上做我需要做的事情就这么简单如gdal_translate -outsize xy -of GTiff infile外文件

Surely I'm using the wrong terms / lingo and I apologize for that... on the command line to do what I would need done it would be as simple as gdal_translate -outsize x y -of GTiff infile outfile

请帮助!

推荐答案

都不行。

重塑仅改变数据的形状,而不改变总大小,因此您可以例如将形状为 1x9 的数组重塑为一个这是 3x3 ,但不是 2x4

Reshape only changes the shape of the data, but not the total size, so you can for example reshape an array of shape 1x9 into one which is 3x3, but not into 2x4.

Resize做类似的事情,但是可以增加大小,在这种情况下,它将用要调整大小的数组元素填充新空间。

Resize does similar thing, but lets you increase the size, in which case it will fill new space with elements of array which is being resized.

您有两种选择:编写可以按您希望的方式进行大小调整的函数,或者使用Python图像库之一(PIL,Pillow ...)应用常见的图像调整大小函数。

You have two choices: write your function which does resizing in the manner you want it to do so, or use one of Python image libraries (PIL, Pillow...) to apply common image resizing functions.

这篇关于调整大小或调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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