numpy basics Flashcards

1
Q

Import NumPy as np

A

import numpy as np

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

Create an array of 10 zeros

A

zero_array = np.zeros(10)
zero_array

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

Create an array of 10 ones

A

ones_array = np.ones(10)
ones_array

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

Create an array of 10 fives

A

fives_array = 5*(np.ones(10))
fives_array

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

Create an array of the integers from 10 to 50

A

ten_fifty_array = np.arange(10,51)
ten_fifty_array

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

Create an array of all the even integers from 10 to 50

A

ten_fifty_even = np.arange(10,51,2)
ten_fifty_even

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

Create a 3x3 matrix with values ranging from 0 to 8

A

matrix1 = np.arange(0,9).reshape(3,3)
matrix1

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

Create a 3x3 identity matrix

A

ident = np.eye(3)
ident

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

Use NumPy to generate a random number between 0 and 1

A

num_1_to_2 = np.random.rand(1)
num_1_to_2

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

Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution

A

random25_normal = np.random.randn(25)
random25_normal

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

Create the following matrix:

A

matrix2 = (np.arange(1,101).reshape(10,10))/100
matrix2

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

Create an array of 20 linearly spaced points between 0 and 1:

A

array20 = np.linspace(0,1,20)
array20

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

mat = np.arange(1,26).reshape(5,5)
mat

give me the subset of this

A

mat[2:5,1:5]

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

mat = np.arange(1,26).reshape(5,5)
mat

give me the subset of this

20

A

mat[3:4,-1]

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

mat = np.arange(1,26).reshape(5,5)
mat

give me the subset of this

array([[2],

[7],

[12]])

A

mat[0:3,1:2]

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

mat = np.arange(1,26).reshape(5,5)
mat

give me the subset of this

‘array([21, 22, 23, 24, 25])’

A

mat[-1,0:5]

17
Q

mat = np.arange(1,26).reshape(5,5)
mat

give me the subset of this

” array([[16, 17, 18, 19, 20],

[21, 22, 23, 24, 25]]) “

A

mat[3:5,0:5]

18
Q

mat = np.arange(1,26).reshape(5,5)
mat

Get the sum of all the values in mat

A

np.sum(mat)

19
Q

mat = np.arange(1,26).reshape(5,5)
mat

find the stanard dev of the matrix numbers

A

np.std(mat)

20
Q

mat = np.arange(1,26).reshape(5,5)
mat

add all colums

A

np.sum(mat,axis = 0)

21
Q
A