Creating and loading arrays

Creating arrays

In [1]:
import numpy as np
print("ones", np.ones(5))
print("arange", np.arange(5))
print("linspace", np.linspace(0., 1., 5))
print("random", np.random.uniform(size=3))
print("custom", np.array([2, 3, 5]))
Out[1]:
ones [ 1.  1.  1.  1.  1.]
arange [0 1 2 3 4]
linspace [ 0.    0.25  0.5   0.75  1.  ]
random [ 0.68361911  0.33585308  0.70733934]
custom [2 3 5]
In [2]:
np.array([[1, 2], [3, 4]])
Out[2]:
array([[1, 2],
       [3, 4]])
In [3]:
np.ones(5, dtype=np.int64)
Out[3]:
array([1, 1, 1, 1, 1])
In [4]:
np.arange(5).astype(np.float64)
Out[4]:
array([ 0.,  1.,  2.,  3.,  4.])

Loading arrays from files

In [5]:
import pandas as pd
In [6]:
data = pd.read_csv('../chapter2/data/nyc_data.csv')
In [7]:
pickup = data[['pickup_longitude', 'pickup_latitude']].values
pickup
Out[7]:
array([[-73.955925,  40.781887],
       [-74.005501,  40.745735],
       ...,
       [-73.978477,  40.772945],
       [-73.987206,  40.750568]])
In [8]:
pickup.shape
Out[8]:
(846945, 2)