0

Explain what below code does? aa=aa[:22]

Import bumpy as np aa=no.array([1,2,3,4,5]) # this will generate an array of [1,2,3,4,5] aa=aa[:22] #??????? aa = np.expand_dims(aa, axis=0)

19th Nov 2020, 9:18 PM
Karzan
2 Respuestas
+ 1
I don't think 'bumpy' is the right module here, it should be 'numpy'. According to me, the correct code should be: import numpy as np aa=np.array([1,2,3,4,5]) #this will generate as array of [1,2,3,4,5] aa=aa[:22] ''' This is pretty meaningless since the array length is 5 which is smaller than 22, so variable 'aa' will remain the same. It would be more meaningful if 'aa[:2:2]' is used since it will do some manipulation and return alternate elements between indexes 0 and 2. ''' aa=np.expand_dims(aa,axis=0) ''' This statement will convert 'aa' form array to matrix i.e., increment in dimension, from 1D(array) to 2D(matrix). axis=0 is mentioned, therefore the number of columns is increased from 1 to the number of elements in the array, in the case of axis=1, the number of rows will be increased from 1 to the number of elements in the array. ''' Hope you find this useful.
22nd Nov 2020, 3:57 PM
Manish Yadav
Manish Yadav - avatar
0
Thank you Manish. You I had a typo for bumpy it should be numpy
22nd Nov 2020, 7:03 PM
Karzan