Introduction to Python
Hugo Bowne-Anderson
Data Scientist at DataCamp
import numpy as np
np_height = np.array([1.73, 1.68, 1.71, 1.89, 1.79])
np_weight = np.array([65.4, 59.2, 63.6, 88.4, 68.7])
type(np_height)
numpy.ndarray
type(np_weight)
numpy.ndarray
np_2d = np.array([[1.73, 1.68, 1.71, 1.89, 1.79], [65.4, 59.2, 63.6, 88.4, 68.7]])
np_2d
array([[ 1.73, 1.68, 1.71, 1.89, 1.79],
[65.4 , 59.2 , 63.6 , 88.4 , 68.7 ]])
np_2d.shape
(2, 5) # 2 rows, 5 columns
np.array([[1.73, 1.68, 1.71, 1.89, 1.79],
[65.4, 59.2, 63.6, 88.4, "68.7"]])
array([['1.73', '1.68', '1.71', '1.89', '1.79'],
['65.4', '59.2', '63.6', '88.4', '68.7']], dtype='<U32')
0 1 2 3 4
array([[ 1.73, 1.68, 1.71, 1.89, 1.79], 0
[ 65.4, 59.2, 63.6, 88.4, 68.7]]) 1
np_2d[0]
array([1.73, 1.68, 1.71, 1.89, 1.79])
0 1 2 3 4
array([[ 1.73, 1.68, 1.71, 1.89, 1.79], 0
[ 65.4, 59.2, 63.6, 88.4, 68.7]]) 1
np_2d[0][2]
1.71
np_2d[0, 2]
1.71
0 1 2 3 4
array([[ 1.73, 1.68, 1.71, 1.89, 1.79], 0
[ 65.4, 59.2, 63.6, 88.4, 68.7]]) 1
np_2d[:, 1:3]
array([[ 1.68, 1.71],
[59.2 , 63.6 ]])
np_2d[1, :]
array([65.4, 59.2, 63.6, 88.4, 68.7])
Introduction to Python