Unwanted extra dimensions in NumPy array

后端 未结 2 1552
[愿得一人]
[愿得一人] 2020-12-18 22:06

I\'ve opened a .fits image:

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

and when I print its s

2条回答
  •  轮回少年
    2020-12-18 22:20

    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)
    

提交回复
热议问题