In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from pandas import DataFrame, Series
In [2]:
np.ones((10, 5)).shape
Out[2]:
In [3]:
np.ones((3, 4, 5), dtype=np.float64).strides
Out[3]:
In [4]:
ints = np.ones(10, dtype=np.uint16)
floats = np.ones(10, dtype=np.float32)
np.issubdtype(ints.dtype, np.integer)
Out[4]:
In [5]:
np.issubdtype(floats.dtype, np.integer)
Out[5]:
In [6]:
np.float64.mro()
Out[6]:
In [7]:
arr = np.arange(8)
arr
Out[7]:
In [8]:
arr.reshape((4, 2))
Out[8]:
In [9]:
arr.reshape((4, 2)).reshape((2, 4))
Out[9]:
In [10]:
arr = np.arange(15)
arr.reshape((5, -1))
Out[10]:
In [12]:
other_arr = np.ones((3, 5))
other_arr.shape
Out[12]:
In [13]:
arr.reshape(other_arr.shape)
Out[13]:
In [15]:
arr = np.arange(15).reshape((5, 3))
arr
Out[15]:
In [16]:
arr.ravel()
Out[16]:
In [17]:
arr.flatten()
Out[17]:
In [18]:
arr = np.arange(12).reshape((3, 4))
arr
Out[18]:
In [19]:
arr.ravel()
Out[19]:
In [20]:
arr.ravel('F')
Out[20]:
In [21]:
arr1 = np.array([[1, 2, 3], [4, 5, 6]])
arr2 = np.array([[7, 8, 9], [10, 11, 12]])
np.concatenate([arr1, arr2], axis=0)
Out[21]:
In [22]:
np.concatenate([arr1, arr2], axis=1)
Out[22]:
In [23]:
np.vstack((arr1, arr2))
Out[23]:
In [24]:
np.hstack((arr1, arr2))
Out[24]:
In [25]:
from numpy.random import randn
arr = randn(5, 2)
arr
Out[25]:
In [26]:
first, second, third = np.split(arr, [1, 3])
first
Out[26]:
In [27]:
second
Out[27]:
In [28]:
third
Out[28]:
In [30]:
np.split(arr, [2])
Out[30]:
In [31]:
arr = np.arange(6)
arr1 = arr.reshape((3, 2))
arr2 = randn(3, 2)
np.r_[arr1, arr2]
Out[31]:
In [32]:
np.c_[np.r_[arr1, arr2], arr]
Out[32]:
In [33]:
np.c_[1:6, -10:-5]
Out[33]:
In [ ]:
In [ ]: