Numpy

Numpy

The Numpy Array Type

Creating Numpy Arrays

Array Creation Examples

Some Array Data Types

Basic Array Manipulations

Array Attributes

Array Indexing

Array Slicing

Copy an Array

Array Manipulation

Universal Functions

Aggregations

Multi-Dimensional Aggregations

Sorting Arrays

Broadcasting

Broadcasting Example

>>> A = np.ones( (2,3) )
>>> b = np.arange(3)
>>> A + b
array([[ 1., 2., 3.],
       [ 1., 2., 3.]])
# A: shape (2,3)
# b: shape (3,) -> (1,3) -> (2,3)

Boolean Arrays

Boolean Operation Example

x = np.random.random( (10,2) )

# number of entries greater than 0.5
np.sum(x > 0.5)

# count entries between values
np.sum( (x > 0.25) & (x < 0.75) )

Boolean Masks

Fancy Indexing