简体   繁体   中英

How to convert a numpy array of dimension (x,y,z) to (x,y,z-1)?

我有一个 numpy 数组 (1471,6,4),我想将它转换为 (1471,6,3)

If by "convert" you mean reshape, you can't, since your new array has less elements than the original one.

But you can basically skip the last channel and only take the first three ones.

new_array = old_array[:,:,:3]

If you don't need the old array, you can just overwrite it. It will look as it has been "converted" to the new shape (but you will loose the 4th channel data)

my_array = my_array[:,:,:3]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM