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)