NumPy数组中多余的尺寸 [英] Unwanted extra dimensions in NumPy array

查看:77
本文介绍了NumPy数组中多余的尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开了一个.fits图片:

I've opened a .fits image:

scaled_flat1 = pyfits.open('scaled_flat1.fit')   
scaled_flat1a = scaled_flat1[0].data

当我打印其形状时:

print scaled_flat1a.shape

我得到以下信息:

(1, 1, 510, 765)

我希望它读为:

(510, 765)

如何摆脱之前的两个?

推荐答案

我假设scaled_flat1a是一个numpy数组?在这种情况下,它应该像reshape命令一样简单.

I'm assuming scaled_flat1a is a numpy array? In that case, it should be as simple as a reshape command.

import numpy as np

a = np.array([[[[1, 2, 3],
                [4, 6, 7]]]])
print(a.shape)
# (1, 1, 2, 3)

a = a.reshape(a.shape[2:])  # You can also use np.reshape()
print(a.shape)
# (2, 3)

这篇关于NumPy数组中多余的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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