Just general python data science stuff Flashcards
how to iterate over dictionary key-values pairs?
for key, value in dictionary.items():
print(key, “ - “, value)
create a np array of all the numbers from 0 to 20
array = np.arange(21)
create a 2d numpy array; all numbers from 0 to 20 in 4 rows of data
array = np.arange(20). reshape(4,5)
check the shape of a np array “array”
array.shape
create a np array of the numbers between 50 and 100, increasing in intervals of 5
array = np.arange(50, 101, 5)
create a np array consisting of all zeros, let’s say with 5 rows of 7 items each.
array = np.zeros((5,7))
create a np array consisting of all ones, let’s say with 4 rows of 2 items each.
array = np.ones((4,2))
create a numpy array full of threes, 10 rows of 3 items
array = np.full((10,3),3)
create a numpy array with 4 numbers, equally spaced between (and including) 0 and 1.
array = np.linspace(0,1, num = 4)
create a numpy array by straight up typing a list of numbers
array = np.array([0,1,2,3,4,5])
iterate over all the items in a multi-dimensional numpy array, and - whatever - prints it
for item in np.ndinter(array):
print(item)
transpose a numpy array
npArrayTransposed = np.transpose(npArray)