Numpy (Wk 3 UCSD / DataCamp) Flashcards
How does a (numpy) array differ from a list?
You can perform mathematical operations element wise on the array (vector arithmetic)
How do you create a numpy array?
np_array = np.array(list) OR np.array([x, y, z])
What happens if you divide 2 np arrays (of the same size)
the output is the an array of the same size, w/ each element the respective quotients
What happens if you create a numpy array of multiple types?
it will convert all to one type (aka type coercion)
what’s the output of np_array > X
Array of Booleans element wise [True, False, etc]
What’s the output of np_array[ np_array > X]
Returns element wise values that meet the condition (product w/ Boolean result)
When do you use parentheses with an array?
When you’re instantiating only (eg, not when you’re setting or sub-setting
How do you create a multi-dimensional np array?
np_array = np.array(list1, list2) OR = np.array( [ [1,2,3], [4,5,6] ] )
How do you get the number of rows and columns of an array?
np_array.shape (attribute of the array)
How do return 2nd element from 3rd row of a 2d np array?
np_array[2,1] OR np_array[2][1]
How do you sub-set multi-dimensional np arrays?
np_array[ x:y, k:j ]
using subsetting, return the entire second row of a np array
np_array[ 1, : ]
How does arithmetic work with multi-dim arrays?
can do all operations. Array X Array, or Array X Vector(s)
Get the mean of the first column of data in a 2D np array
np.mean(np_array[ : , 0]
summary stats functions np arrays
np.mean(), np.median(), np.std()