Reputation: 6152
Given a sliced numpy array as follows:
b = [a[..., i] for i in a.shape[-1]]
What is the most simple way I can recreate a
from b
?
Something like:
for i in range(a.shape[-1]):
c[..., i] = b[i]
Upvotes: 0
Views: 72
Reputation: 281529
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.
The reverse operation is
c = numpy.rollaxis(b, axis=0, start=b.ndim)
Upvotes: 1