小编典典

如何仅展平numpy数组的某些维度

all

有没有一种快速的方法来“亚展平”或展平 numpy 数组中的一些第一个维度?

例如,给定一个 numpy 维度数组(50,100,25),结果维度将是(5000,25)


阅读 92

收藏
2022-06-30

共1个答案

小编典典

看看numpy.reshape

>>> arr = numpy.zeros((50,100,25))
>>> arr.shape
# (50, 100, 25)

>>> new_arr = arr.reshape(5000,25)
>>> new_arr.shape   
# (5000, 25)

# One shape dimension can be -1. 
# In this case, the value is inferred from 
# the length of the array and remaining dimensions.
>>> another_arr = arr.reshape(-1, arr.shape[-1])
>>> another_arr.shape
# (5000, 25)
2022-06-30