import numpy as np
# Set seed for reproducibility
np.random.seed(seed=123)
sk_id_curr = np.array(100001)
print ("sk_id_curr: ", sk_id_curr)
# Number of dimensions
print ("sk_id_curr ndim: ", sk_id_curr.ndim)
# Dimensions
print ("sk_id_curr shape:", sk_id_curr.shape)
# Size of elements
print ("sk_id_curr size: ", sk_id_curr.size)
# Data type
print ("sk_id_curr dtype: ", sk_id_curr.dtype)
('sk_id_curr: ', array(100001)) ('sk_id_curr ndim: ', 0) ('sk_id_curr shape:', ()) ('sk_id_curr size: ', 1) ('sk_id_curr dtype: ', dtype('int64'))
sk_id_curr = np.array([100001, 100005, 100013, 100028, 100038, 100042])
print ("sk_id_curr:", sk_id_curr)
print ("sk_id_curr ndim: ", sk_id_curr.ndim)
print ("sk_id_curr shape:", sk_id_curr.shape)
print ("sk_id_curr size: ", sk_id_curr.size)
print ("sk_id_curr dtype: ", sk_id_curr.dtype)
('sk_id_curr:', array([100001, 100005, 100013, 100028, 100038, 100042])) ('sk_id_curr ndim: ', 1) ('sk_id_curr shape:', (6,)) ('sk_id_curr size: ', 6) ('sk_id_curr dtype: ', dtype('int64'))
sk_id_curr = np.array([[100001, 100005], [100013, 100028], [100038, 100042]])
print ("sk_id_curr:", sk_id_curr)
print ("sk_id_curr ndim: ", sk_id_curr.ndim)
print ("sk_id_curr shape:", sk_id_curr.shape)
print ("sk_id_curr size: ", sk_id_curr.size)
print ("sk_id_curr dtype: ", sk_id_curr.dtype)
('sk_id_curr:', array([[100001, 100005], [100013, 100028], [100038, 100042]])) ('sk_id_curr ndim: ', 2) ('sk_id_curr shape:', (3, 2)) ('sk_id_curr size: ', 6) ('sk_id_curr dtype: ', dtype('int64'))
print ("np.zeros((2,2)):", np.zeros((2,2)))
print ("np.ones((2,2)):", np.ones((2,2)))
print ("np.eye((2)):", np.eye((2)))
print ("np.random.random((2,2)):", np.random.random((2,2)))
('np.zeros((2,2)):', array([[0., 0.], [0., 0.]])) ('np.ones((2,2)):', array([[1., 1.], [1., 1.]])) ('np.eye((2)):', array([[1., 0.], [0., 1.]])) ('np.random.random((2,2)):', array([[0.69646919, 0.28613933], [0.22685145, 0.55131477]]))
sk_id_curr = np.array([100001, 100005, 100013, 100028, 100038, 100042])
print ("sk_id_curr[0]: ", sk_id_curr[0])
sk_id_curr[0] = 0
print ("sk_id_curr: ", sk_id_curr)
('sk_id_curr[0]: ', 100001) ('sk_id_curr: ', array([ 0, 100005, 100013, 100028, 100038, 100042]))
sk_id_curr = np.array([[100001, 100005, 111111], [100013, 100028, 222222], [100038, 100042, 333333]])
print (sk_id_curr)
print ("sk_id_curr column 1: ", sk_id_curr[:, 1])
print ("sk_id_curr row 0: ", sk_id_curr[0, :])
print ("sk_id_curr rows 0,1,2 & cols 1,2:", sk_id_curr[:3, 1:3])
[[100001 100005 111111] [100013 100028 222222] [100038 100042 333333]] ('sk_id_curr column 1: ', array([100005, 100028, 100042])) ('sk_id_curr row 0: ', array([100001, 100005, 111111])) ('sk_id_curr rows 0,1,2 & cols 1,2:', array([[100005, 111111], [100028, 222222], [100042, 333333]]))
sk_id_curr = np.array([[100001, 100005, 111111], [100013, 100028, 222222], [100038, 100042, 333333]])
print ("sk_id_curr:", sk_id_curr)
print ("sk_id_curr > 111111:", sk_id_curr > 111111)
print ("sk_id_curr[sk_id_curr > 111111]:", sk_id_curr[sk_id_curr > 111111])
('sk_id_curr:', array([[100001, 100005, 111111], [100013, 100028, 222222], [100038, 100042, 333333]])) ('sk_id_curr > 111111:', array([[False, False, False], [False, False, True], [False, False, True]])) ('sk_id_curr[sk_id_curr > 111111]:', array([222222, 333333]))
x = np.array([[1,2], [3,4]], dtype=np.float64)
y = np.array([[1,2], [3,4]], dtype=np.float64)
print ("x + y:", np.add(x, y)) # or x + y
print ("x - y:", np.subtract(x, y)) # or x - y
print ("x * y:", np.multiply(x, y)) # or x * y
('x + y:', array([[2., 4.], [6., 8.]])) ('x - y:', array([[0., 0.], [0., 0.]])) ('x * y:', array([[ 1., 4.], [ 9., 16.]]))
a = np.array([[1,2,3], [4,5,6]], dtype=np.float64) # we can specify dtype
b = np.array([[7,8], [9,10], [11, 12]], dtype=np.float64)
print (a.dot(b))
[[ 58. 64.] [139. 154.]]
x = np.array([[1,2],[3,4]])
print (x)
print ("sum all: ", np.sum(x)) # adds all elements
print ("sum by col: ", np.sum(x, axis=0)) # add numbers in each column
print ("sum by row: ", np.sum(x, axis=1)) # add numbers in each row
[[1 2] [3 4]] ('sum all: ', 10) ('sum by col: ', array([4, 6])) ('sum by row: ', array([3, 7]))
print ("x:", x)
print ("x.T:", x.T)
('x:', array([[1, 2], [3, 4]])) ('x.T:', array([[1, 3], [2, 4]]))
x = np.array([[1,2], [3,4]])
y = np.array([5, 6])
z = x + y
print ("z:", z)
('z:', array([[ 6, 8], [ 8, 10]]))
x = np.array([[1,2], [3,4], [5,6]])
print (x)
print ("x.shape: ", x.shape)
y = np.reshape(x, (2, 3))
print ("y.shape: ", y.shape)
print ("y:", y)
[[1 2] [3 4] [5 6]] ('x.shape: ', (3, 2)) ('y.shape: ', (2, 3)) ('y:', array([[1, 2, 3], [4, 5, 6]]))