0

I have a numpy array of dimension (a,b,c). And I want to slice it to over c'th dimension. For eg: A numpy array of shape (2,3,4), I want to iterate over 4 arrays of dimension (2,3).

So far I have been doing

for i in range(c):
    arr = A[::,i]

But this doesn't compute the right thing. How can I compute this?

2
  • range(A.shape[-1]) Commented Mar 30, 2019 at 12:36
  • I have all the dimensions a,b,c. I want to slice the numpy array to get four 2*3 arrays. Commented Mar 30, 2019 at 12:42

2 Answers 2

1

Doesn't it also take a comma between the colons? Like so : arr = A[:, :, i]

Sign up to request clarification or add additional context in comments.

Comments

0

You are missing a comma. Your code should look like:

for i in range(c):
    arr = A[:,:,i]

BTW the code above is computing the right thing, but you are writing a statement that doesn't solve your problem :)

1 Comment

Can you provide some links to understand these kind of syntax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.