Articles → NUMPY → Arrays In Numpy

Arrays In Numpy






Arrays




  1. Vectors
  2. Matrices

Vectors




import numpy as np

my_list = [1,2,3]
my_list
print(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]]
print(np.array(my_matrix))


Picture showing the output of arrays of arrays
Click to Enlarge


Accessing The Elements In Matrices




  1. Double bracket approach
  2. 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])


  3. Single bracket approach
  4. 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