Lesson 6 Numpy Flashcards
Import numpy and check what version you have
import numpy as np
numpy.__version__
Create an array from this list my_list = [1,2,3]
np.array(my_list)
Create an array from the matrix my_matrix = [[1,2,3],[4,5,6],[7,8,9]]
np.array(my_matrix)
my_arr = np.array([1, 2, 3, 4, 5, 6, 7, 8])
Add the values 1,2 to the array above.
np.append(my_arr, [1,2])
my_arr = np.array([1, 2, 3, 4, 5, 6, 7, 8])
Delete index 1 from my array
np.delete(my_arr, 1)
Arrange the numbers in ascending order: another_arr = np.array([2, 1, 5, 3, 7, 4, 6, 8])
np.sort(another_arr)
Return evenly spaced values within a given interval. Do this for the values from 0-9
np.arange(0,10)
Return evenly spaced values within a given interval. Do this for the values from 0-10 every 2 values
np.arange(0,11,2)
Generate a matrix of zeros - one row, 3 columns
np.zeros(3)
Generate a matrix of zeros - 10 rows, 10 cols
np.zeros((10,10))
Generate a matrix of ones, 5 rows, 5 cols
np.ones((5,5))
Return evenly spaced numbers over a specified interval. Do this for the numbers 0-10 with 3 numbers.
np.linspace(0,10,3)
Return evenly spaced numbers over a specified interval. Do this for the numbers 0-20 with 50 numbers.
np.linspace(0,20,50)
Create an identity matrix for 8 rows.
np.eye(8)
Return 3 random numbers (0-1) in an array.
np.random.rand(3)
Return random numbers (0-1) in a matrix with 4 rows and 4 cols.
np.random.rand(4,4)
Return a random sample from the “standard normal” distribution. Do this for 3 numbers.
np.random.randn(3)
Return a random sample from the “standard normal” distribution. Do this for 3 numbers.
np.random.randn(3)
Return random integers from 1-99
np.random.randint(1,100)