y a s n p a = n p . a r r a y ( [ 1 , 2 , 3 ] ) # C r e a t e a r a n k 1 a r r a y p r i n t t y p e ( a ) # P r i n t s " < t y p e ' n u m p y . n d a r r a y ' > " p r i n t a . s h a p e # P r i n t s " ( 3 , ) " p r i n t a [ 0 ] , a [ 1 ] , a [ 2 ] # P r i n t s " 1 2 3 " a [ 0 ] = 5 # C h a n g e a n e l e m e n t o f t h e a r r a y p r i n t a # P r i n t s " [ 5 , 2 , 3 ] " b = n p . a r r a y ( [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ) # C r e a t e a r a n k 2 a r r a y p r i n t b . s h a p e # P r i n t s " ( 2 , 3 ) " p r i n t b [ 0 , 0 ] , b [ 0 , 1 ] , b [ 1 , 0 ] # P r i n t s " 1 2 4 " # - - - - - a = n p . z e r o s ( ( 2 , 2 ) ) # C r e a t e a n a r r a y o f a l l z e r o s p r i n t a # P r i n t s " [ [ 0 . 0 . ] # [ 0 . 0 . ] ] " b = n p . o n e s ( ( 1 , 2 ) ) # C r e a t e a n a r r a y o f a l l o n e s p r i n t b # P r i n t s " [ [ 1 . 1 . ] ] " c = n p . f u l l ( ( 2 , 2 ) , 7 ) # C r e a t e a c o n s t a n t a r r a y p r i n t c # P r i n t s " [ [ 7 . 7 . ] # [ 7 . 7 . ] ] " d = n p . e y e ( 2 ) # C r e a t e a 2 x 2 i d e n t i t y m a t r i x p r i n t d # P r i n t s " [ [ 1 . 0 . ] # [ 0 . 1 . ] ] " e = n p . r a n d o m . r a n d o m ( ( 2 , 2 ) ) # C r e a t e a n a r r a y f i l l e d w i t h r a n d o m v a l u e s p r i n t e # M i g h t p r i n t " [ [ 0 . 9 1 9 4 0 1 6 7 0 . 0 8 1 4 3 9 4 1 ] # [ 0 . 6 8 7 4 4 1 3 4 0 . 8 7 2 3 6 6 8 7 ] ] " Numpy Numpy is the core library for scientific computing in Python. It provides a high- performance multidimensional array object (MATLAB style), and tools for working with these arrays. Arrays A numpy array is a grid of values, all of the same type, and is indexed by a tuple of nonnegative integers. The number of dimensions is the rank of the array; the shape of an array is a tuple of integers giving the size of the array along each dimension. We can initialize numpy arrays from nested Python lists, and access elements using square brackets. Numpy also provides many functions to create arrays. 19 / 42