1

What basically the commas do in slicing nd array in NumPy?

E.g. for a 3d array, what do these mean? a[1,2::] a[:2,3:] a[1:2,:]

I means commas in general, how do these thing work while slicing? I know about a[start:stop:step] but having hard time understanding what to commas imply.

Edit: I've read on few websites about slicing using tuple,that is what I don't understand. How does slicing with tuple work?

Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34
cyclonejet
  • 41
  • 1
  • 6
  • Does this answer your question? [Python Array Slice With Comma?](https://stackoverflow.com/questions/9972391/python-array-slice-with-comma) – Shubham Srivastava Sep 09 '20 at 06:29
  • The comma separates the indices for each dimension. With a 3d array you may see up to 2 commas (3 indices). Technically the comma creates a tuple, but you don't usually need to focus on that. Don't forget to read some basic `numpy` documentation. – hpaulj Sep 09 '20 at 06:29
  • @ShubhamSrivastava @hpaulj So it basically comes down to slicing with tuple. How does slicing with tuple work? Is there any general syntax like `a[1,::]` selects first element from dim 0. Something of this sort. – cyclonejet Sep 09 '20 at 06:43
  • Could you be more specific - like share a command and write specifically what didn't you understand about the outcome, and what were you expecting. SO isn't really to provide software development training, but rather to solve particular programming (-related) problems. – Grzegorz Skibinski Sep 09 '20 at 06:46
  • Don't you have an interactive python session running with numpy loaded. It's a lot easier to understand when you can test bits of code. `arr[ index1, index2, index3]`. Each `index` can be an integer, a slice, or a list/array. Each selects something from a different dimension. – hpaulj Sep 09 '20 at 06:55

0 Answers0