简体   繁体   English

切片numpy数组

[英]un-slicing numpy arrays

Given a sliced numpy array as follows: 给定一个切片的numpy数组,如下所示:

b = [a[..., i] for i in a.shape[-1]]

What is the most simple way I can recreate a from b ? 我可以从b重新创建a的最简单方法是什么?

Something like: 就像是:

for i in range(a.shape[-1]):
    c[..., i] = b[i]

Instead of that list comprehension, your original operation should have been 而不是列表理解,您原来的操作应该是

b = numpy.rollaxis(a, axis=-1)

which produces a view of a as a new array instead of a list of arrays. 其产生的视图a作为新的数组,而不是阵列的列表。

The reverse operation is 反向操作是

c = numpy.rollaxis(b, axis=0, start=b.ndim)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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