Print from specific positions in NumPy array
Question:
I am new to NumPy and I have created the following array:
import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
and I am wondering if there is a way to print a number from a specific position in the array.
Let’s say I wanted to print number 7, and ONLY number 7. Would that be possible?
Answers:
Seriously??!?
Print third row (index = 2), first column (index = 0)
>>> import numpy as np
>>> a = np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> print a[2][0]
7
>>> b
array([[ 0, 1, 2, 3],
[10, 11, 12, 13],
[20, 21, 22, 23],
[30, 31, 32, 33],
[40, 41, 42, 43]])
>>> b[2,3]
23
The syntax is [row,column] each indexed from zero, so b[2,3] means third row, fourth column of b.
I am new to NumPy and I have created the following array:
import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
and I am wondering if there is a way to print a number from a specific position in the array.
Let’s say I wanted to print number 7, and ONLY number 7. Would that be possible?
Seriously??!?
Print third row (index = 2), first column (index = 0)
>>> import numpy as np
>>> a = np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> print a[2][0]
7
>>> b
array([[ 0, 1, 2, 3],
[10, 11, 12, 13],
[20, 21, 22, 23],
[30, 31, 32, 33],
[40, 41, 42, 43]])
>>> b[2,3]
23
The syntax is [row,column] each indexed from zero, so b[2,3] means third row, fourth column of b.