Python Part 4: Numpy Flashcards

1
Q

axis = 0 in a 2d array

vertical or horizontal?

A

vertical

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

axis = 1

vertical or horizontal for 2d array?

A

horizontal

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

create an array with the numbers 1, 2, 3, 4, 5

A

arr = np.array([1,2,3,4,5])

arr = np.arange(1,6)

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

create an array of 10 zeros

create an array of ones with the dimensions 3x4

A

arr1 = np.zeros(10)
arr2 = np.ones((3,4))

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

create an array with a range of numbers

  • create an array with 0,1,2
  • create an array with 3,4,5
A

np.arange(range)

zB
arr1=np.arange(3)
arr2=np.arange(3,6)

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

np.random.randint(): 4 occurrences

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

numpy.random.rand():

A

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

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

np.mean(): 4 occurrences

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

Standard Deviation?

A

np.std(array)

also

np.std(array, axis = x)

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

Variance ?

A

np.var(array)

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

Array Reshaping ?

A

arr.reshape(new dimensions)

arr = np.arange(12)
newarr = arr.reshape(4,3)
print(newarr)

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

arr = np.arange(12)
newarr = arr.reshape(4,3)
print(newarr)

output?

A

[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]
[ 9 10 11]]

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

arr1=np.arange(3)
arr2=np.arange(3,6)

output arrays?

A

[0 1 2]
[3 4 5]

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

numpy.random.randn():

A

Generate random numbers from a standard normal distribution

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

numpy.random.randint():

A

Generate random integers between specified limits.

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

numpy.random.shuffle():

A

Shuffle the elements of an array randomly.

17
Q

initialise an 1x5 array of random integers smaller than 16

A

xarr1=np.random.randint(16,size=5)

18
Q

initialise a 3x3 array of random integers >= 7 and < 12

A

xarr2=np.random.randint(7,12,size=(3,3))

19
Q

Initialise a 3x5 array, choosing numbers randomly from the set (3, 5, 7, 9)

A

x = random.choice([3, 5, 7, 9], size=(3, 5))