from numpy import *

# one-dimensional array creation
a = array([0,1,2,3])
a = arange(0,1,0.1)             # [0,1)
a = linspace(0,1,10)            # [0,1], 10 elements

# multi-dimensional array creation
a = array([[0,1,2,3],[4,5,6,7],[8,9,10,11]])
a = arange(12).reshape(3,4)

# array properties
a.shape                         # (3,4)
a.size                          # 3 * 4 = 12
a.ndim                          # len(a.shape) = 2
a.dtype                         # int32

# array creation from given patterns
b = zeros((3,4))                # filled with zeros
b = ones((3,4))                 # filled with ones
b = empty((3,4))                # original value in memory
b = eye(3)                      # 3x3, 1 on main diagonal, 0 otherwise
b = random.random((3,4))        # filled with random value in [0,1)

# array creation from function
def f(i,j):
    return 2 * i + j + 1
b = fromfunction(f,(3,4))

# array creation with explicit dtype
a = array([[0,1,2,3],[4,5,6,7],[8,9,10,11]], dtype=int32)
b = fromfunction(f,(3,4),dtype=int32)

# array operations
c = a + b                       # element-wise add
c = a - b                       # element-wise minus
c = a * b                       # element-wise mult
c = a / b                       # element-wise div
c = a % b                       # element-wise mod
c = a ** b                      # element-wise power

c = exp(a)                      # element-wise exp
c = sqrt(a)                     # element-wise sqrt
c = sin(a)                      # element-wise sin

c = hstack((a,b))               # horizontal stack
c = vstack((a,b))               # vertical stack

c = hsplit(a,2)                 # horizontally split a into 2 parts
c = hsplit(a,(1,3))             # horizontally split a before index 1 and 3
c = vsplit(a,3)                 # vertically split a into 3 parts
c = vsplit(a,(2,))              # vertically split a before index 2

a.sum()                         # sum of all elements
a.sum(axis=0)                   # sum of all rows
a.sum(axis=1)                   # sum of all columns
a.cumsum(axis=0)                # cumulative sum of rows
a.cumsum(axis=1)                # cumulative sum of columns

b.transpose()                   # transpose, equal to a.T
b.conj()                        # conjugate
b.ravel()                       # flatten
b.resize(4,3)                   # resize, equal to a = a.reshape(4,3)

# indexing and slicing (shallow copy)
c = a[0,0]
c = a[0:2,1:4]

i = array([0,2])                # row 0 and 2
j = array([0,1,3])              # column 0, 1 and 3
c = a[ix_(i,j)]                 # subarray indexed by [0,2]x[0,1,3]

i = array([0,1,2,1,2,2])        # [0,0], [1,3], [2,1], [1,2], [2,1], [2,3]
j = array([0,3,1,2,1,3])        # j.ndim = i.ndim
c = a[i,j]                      # array([a[0,0], a[1,3], a[2,1], a[1,2], a[2,1], a[2,3]])

b = a > 5                       # bool array
c = a[b]                        # pick from a where b is true

# deep copy
c = a.copy()                    # deep copy though not named deepcopy

Links: