Articles → NUMPY → Arrays in NumPy

Arrays in NumPy






Arrays









Vectors




import numpy as np

my_list = [1,2,3]
my_list
np.array(my_list)


Picture showing the output of one-dimensional array

Click to Enlarge


Matrices




import numpy as np

my_matrix = [[1,2,3],[4,5,6],[7,8,9]]
np.array(my_matrix)


Picture showing the output of arrays of arrays

Click to Enlarge


Accessing the elements in matrices






import numpy as np

my_matrix = np.array([[1,2,3],[4,5,6],[7,8,9]])

# double bracket approach
print(my_matrix[0][1])




import numpy as np

my_matrix = np.array([[1,2,3],[4,5,6],[7,8,9]])

# single bracket approach
print(my_matrix[0, 1])



Posted By  -  Karan Gupta
 
Posted On  -  Monday, March 18, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250