How do I re-shape an array with shape(band,row,column) to (row,column,band)?

后端 未结 2 1863
傲寒
傲寒 2021-01-26 21:06

I have a NumPy array with shape(370,275,210) and I want to re-shape it to (275,210,370). How would I achieve this in Python? 370 is the number of bands,275 is the number of rows

相关标签:
2条回答
  • 2021-01-26 21:17

    Actually, I suppose that you need to swap the axis 0 with 2.

    np.swapaxes(x, 0, 2)
    

    That is probably an hyperspectral image?

    0 讨论(0)
  • 2021-01-26 21:35

    You can use np.moveaxis()

    >>> a = np.zeros((370, 275, 210))
    >>> a.shape
    (370, 275, 210)
    >>> a = np.moveaxis(a, 0, 2)
    >>> a.shape
    (275, 210, 370)
    
    0 讨论(0)
提交回复
热议问题