import numpy as np
data = np.array([[1, 1.5, 2], [5, 3, 1]])
data.shape
data.dtype
data.ndim
np.zeros((3, 6))
np.empty((2, 4))
np.arange(10)
np.arange(10, dtype = 'float64')
np.arange(10 == 'float64').dtype
a1 = np.array([1, 2, 3, 4.5], dtype=np.float64)
a1
a1.dtype
# you can convert data type of an array.
#note that the fractional part is turnicated
a2 = a1.astype(np.int64)
a2
a1 = np.array([1, 2, 3, 4])
a1 * a1
1 / a1
a1 ** 4
a2 = np.array([4, 3, 2, 1])
a1 > a2
a1 = np.arange(10)
a1
# changing index 2, 3, 4 (not 5) to 2000
a1[2: 5] = 2000
# a1 slice is a1 in subset index 2, 3, 4
a1s = a1[2:5]
a1s
# remember, a1s is not a new list, new variable,
# its just a subsect of a1, a1s is a1 but dealing,
# with a small group of a1 and anything affecting,
# a1s will affect a1
a1
a1s[1] = 10
a1s
a1
a3d = np.array([[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]]])
a3d
# 0 chooses which super list (the first list)
# 1 chooses which sub list (the second list)
# 2 chooses which number in the list
a3d[0][1][2]
a3d[0, 1, 2]
a3d[0] = 5
a3d
a2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
a2d
a2d[:2]
a2d[:2, 1:]
a = np.arange(18).reshape(3, 6)
a
a.T
# T is transpose
a.swapaxes(0,1)
np.dot(a.T, a)
#a.t @ a
a = np.arange(5)
a
np.sqrt(a)
np.exp(a)
b = np.arange(4, -1, -1)
b
# start, stop, steps, start at 4, stop at -1, in increments of subtracting 1
c = a / 3
c
# r can be whatever, its just a place holder
#modf calculates intigral fractions
i , r = np.modf(c)
i
r
a = np.arange(5) +1
a
b = np.arange(5) + 6
b
condition = np.array([True, False, True, True, False])
condition
# input x if c (condition) is true, else (false), input y
[(x if c else y) for x, y, c in zip(a, b, condition)]
from numpy import random as rng
a = rng.standard_normal((4, 4))
a
a > 0
np.where(a > 0, 1, -1)
a = np.arange(12).reshape(3,4) + 1
a
a.mean(axis = 1)
a.mean(axis = 0)
a.cumsum(axis = 0)
names = np.array(["Bob", "Will", "Joe", "Bob", "will", "Joe", "Joe"])
names
np.unique(names)
sorted(set(names))