Numpy Cheat Sheet: Umpy Umerical Ython
Numpy Cheat Sheet: Umpy Umerical Ython
ndarray1[ndarray1 < 0] = 0 *
5. Boolean arrays methods
Created By: Arianne Colton and Sean Chen If ndarray1 is two-dimensions, ndarray1 < 0 If at least one ndarray1.any()
*
creates a two-dimensional boolean array. value is True
If all values are ndarray1.all()
True
Numpy (Numerical Python) COMMON OPERATIONS
1. Transposing Note: These methods also work with non-boolean
What is NumPy? Default data type is np.float64. This is A special form of reshaping which returns a view arrays, where non-zero elements evaluate to True.
** equivalent to Pythons float type which is 8 on the underlying data without copying anything.
Foundation package for scientific computing in Python bytes (64 bits); thus the name float64.
ndarray1.transpose() or 6. Sorting
Why NumPy? If casting were to fail for some reason,
*** TypeError will be raised. ndarray1.T or Inplace sorting ndarray1.sort()
Numpy ndarray is a much more efficient way
of storing and manipulating numerical data ndarray1.swapaxes(0, 1)
than the built-in Python data structures. Return a sorted sorted1 =
SLICING (INDEXING/SUBSETTING) 2. Vectorized wrappers (for functions that np.sort(ndarray1)
Libraries written in lower-level languages, such copy instead of
as C, can operate on data stored in Numpy Slicing (i.e. ndarray1[2:6]) is a view on take scalar values) inplace
ndarray without copying any data. the original array. Data is NOT copied. Any math.sqrt() works on only a scalar
modifications (i.e. ndarray1[2:6] = 8) to the
N-DIMENSIONAL ARRAY (NDARRAY) np.sqrt(seq1) # any sequence (list, 7. Set methods
view will be reflected in the original array.
ndarray, etc) to return a ndarray
What is NdArray? Instead of a view, explicit copy of slicing via : Return sorted np.unique(ndarray1)