Guys please help,some1 explain to me the concept of using the (:) after the number -of row and columns -and before it. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Guys please help,some1 explain to me the concept of using the (:) after the number -of row and columns -and before it.

https://code.sololearn.com/cOn7y4tx0k8L/?ref=app

8th Sep 2022, 2:28 PM
Kawtar
Kawtar - avatar
3 Answers
+ 2
Hi! lesson 34.1 list slices (python course for beginners)
8th Sep 2022, 3:49 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Kawtar Chicha I modified your code so that the numbers are not confusing: import numpy as np A = np.array([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) print(A[:2, 2:]) result is [[3] [6]] You can visualize the indexing as: [ [0, 1, 2], --> 0 [0, 1, 2], --> 1 [0, 1, 2] --> 2 ] The first slice :2 selects the indices going downward from index 0 but not including index 2 [0, 1, 2], --> 0 [0, 1, 2], --> 1 or [1, 2, 3], [4, 5, 6], The second slice 2: selects the indices going to the left starting from index 2 [ 2], [ 2], or [ 3] [ 6]
8th Sep 2022, 11:12 PM
Bob_Li
Bob_Li - avatar
+ 1
I do not know much about numpy but you are slicing the array/list when using ':'.Take a look at this: https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-list-slicing/
8th Sep 2022, 2:38 PM
Justice
Justice - avatar