Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个 numpy 数组:
[[1,2], [3,4], [5,6,7]]
是否有任何紧凑的方法来修剪阵列并使其沿第二维对齐,即
[[1,2], [3,4], [5,6]]
切片是否适用于 numpy 数组?如果是这样,下面的代码应该可以解决问题。
array = [[1,2], [3,4], [5,6,7]] array = numpy.array([a[:2] for a in array])
我不确定切片是否适用于 numpy 数组,所以如果它是错误的,我将删除这个答案。