numpy basics Flashcards
Import NumPy as np
import numpy as np
Create an array of 10 zeros
zero_array = np.zeros(10)
zero_array
Create an array of 10 ones
ones_array = np.ones(10)
ones_array
Create an array of 10 fives
fives_array = 5*(np.ones(10))
fives_array
Create an array of the integers from 10 to 50
ten_fifty_array = np.arange(10,51)
ten_fifty_array
Create an array of all the even integers from 10 to 50
ten_fifty_even = np.arange(10,51,2)
ten_fifty_even
Create a 3x3 matrix with values ranging from 0 to 8
matrix1 = np.arange(0,9).reshape(3,3)
matrix1
Create a 3x3 identity matrix
ident = np.eye(3)
ident
Use NumPy to generate a random number between 0 and 1
num_1_to_2 = np.random.rand(1)
num_1_to_2
Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution
random25_normal = np.random.randn(25)
random25_normal
Create the following matrix:
matrix2 = (np.arange(1,101).reshape(10,10))/100
matrix2
Create an array of 20 linearly spaced points between 0 and 1:
array20 = np.linspace(0,1,20)
array20
mat = np.arange(1,26).reshape(5,5)
mat
give me the subset of this
mat[2:5,1:5]
mat = np.arange(1,26).reshape(5,5)
mat
give me the subset of this
20
mat[3:4,-1]
mat = np.arange(1,26).reshape(5,5)
mat
give me the subset of this
array([[2],
[7],
[12]])
mat[0:3,1:2]