IDC410 Machine Learning

Numpy

ndarray

It is a numpy array

Making ndarrays

From a list

mylist =[[1,2,3,4],[5,6,7,8]]
myarr = np.array(mylist, dtype='float')

Using placeholder functions

np.zeros(size, [dtype])
np.ones(size, [dtype])
np.arange(start, stop, [stepsize])
np.full((size), elim, [dtype]) # same as fill

Using miscellaneous functions

np.random.rand(size, [dtype])
np.linspace(start, stop, length)

Matrices

np.reshape(arr, newsize)
nparr.flatten(order=['C', 'F']) # row, column
nparr.T
nparr.size
# Indexing
nparr[rows, columns]

Functions on arrays

Unary

arr.max([axis=axis])
arr.min([axis=axis])
arr.sum([axis=axis])
arr.cumsum([axis=axis])
np.sort(arr, [axis=axis], [kind=method], [order=field])

Binary

a+b
a*b
np.row_stack()
np.column_stack()
np.hsplit()
np.vsplit()
np.append()

Linear Algebra

np.linalg.solve(a, b) # solves AX = B
np.linalg.matrix_rank()
np.trace()
np.linalg.det()
np.linalg.matrix_power()

IO

np.load
np.loadz
np.save
np.savez