NumPy & SciPy Flashcards
create three-dimensional array of floats
import numpy
x = y = z = 5
zeros((x, y, z), np.float)
get array/matrix dimensions
a.shape
get array/matrix datatype
a.dtype
given an array a, make a new array of same dimension and data type
x = zeros(a.shape, a.dtype)
create a list of uniformly spaced coordinates
linspace(start, end, steps)
construct array from list
array(list)
construct 2D-array from two lists
array([x, y])
from array to list
a.tolist()
convert to array
asarray(list)
change array dimensions
a.shape = (3, 2) a = a.reshape(3, 2)
get number of elements in array
a.size
set a[2] and a[3] equal to 5
a[2:4] = 5
set last element equal to first
a[-1] = a[0]
set all elements of array equal to 0
a[:] = 0
a[:, :] = 0
a.fill(0)
print column k
print a[:, k]