Lecture 1 - Numpy Operations 1 Flashcards
How to convert a list to np array?
np.array(list)
this can also be used to copy another np array
Are np ndarrays mutable?
Yes, be careful with this and copy when necessary using np.array
Does np support ragged arrays?
No
How to create a blank np array?
- np.empty
- np.zeroes
- np.ones
- np.full
How to generate random numbers in np ndarrays?
np.random.randint(a,b,shape)
np.random.uniform(a,b,shape)
np.random.normal(mean,std,shape)
Generate sequence like np ndarrays.
np.arange(a,b,step) - exclusive
np.linspace(a,b,step) - inclusive
How to save to file using numpy?
np.savetcxt(arr,name)
slicing format
start : end: step
Rules for indexing
no colon - take specific
one colon - take range
two colons - range with step
Difference between slicing and indexing?
slicing doesn’t change the rank of the array, it picks a subset
indexing typically does reduce a rank, it selects a rectangular region with ranks less
x[::-1]
Reversing
x[:,0]
All rows, first column
x[0,:]
First row all columns