Lecture 1 - Numpy Operations 1 Flashcards

1
Q

How to convert a list to np array?

A

np.array(list)
this can also be used to copy another np array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Are np ndarrays mutable?

A

Yes, be careful with this and copy when necessary using np.array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Does np support ragged arrays?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to create a blank np array?

A
  • np.empty
  • np.zeroes
  • np.ones
  • np.full
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to generate random numbers in np ndarrays?

A

np.random.randint(a,b,shape)
np.random.uniform(a,b,shape)
np.random.normal(mean,std,shape)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Generate sequence like np ndarrays.

A

np.arange(a,b,step) - exclusive
np.linspace(a,b,step) - inclusive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to save to file using numpy?

A

np.savetcxt(arr,name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

slicing format

A

start : end: step

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Rules for indexing

A

no colon - take specific
one colon - take range
two colons - range with step

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Difference between slicing and indexing?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

x[::-1]

A

Reversing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

x[:,0]

A

All rows, first column

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

x[0,:]

A

First row all columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly