numpy basics Flashcards
import the numpy library
import numpy as np
in a 2-D array, what are the axes labels for row and column?
rows - axis 0
cols - axis 1
in a 3-D array what are the axes numbered as for rows, columns and array?
rows - axis 0
cols - axis 1
array - axis 2
create an array in numpy
a = np.array([2,3,5])
create a 2-D array in numpy
two_d = np.array([(3,3,6),(1,4,7)])
create a 3-D array in numpy
c = np.array([[(3,4),(1,3)],[(25,2),(1,55)]])
create an array of zeroes as integers with a length of 5
x = np.zeros(5, dtype=int)
create a 2-d array of zeroes as integers, with dimensions of 5 rows by 3 columns
x = np.zeros((5,3),dtype=int)
create an array of even numbers from 2 -> 46 using numpy
a = np.arange(2,47,2)
create an array of 10 evenly spaced values between 0 and 64 inclusive
a = np.linspace(0,65,10)
create a 3 x 5 matrix (3 rows, 5 columns) filled with the number 10
a = np.full((3,5),10)
create an identity matrix measuring 3x3
np.eye(3)
create a 2x8 matrix (row x col) filled with random numbers
np.random.random((2,8))
see row x col dimensions of an array
a.shape
see if 1-d, 2-d, 3-d, etc of an array
a.ndim