In [4]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [7]:
points = np.arange(-5,5,0.01)
In [8]:
dx,dy = np.meshgrid(points, points)
In [9]:
dx
Out[9]:
In [10]:
dy
Out[10]:
In [11]:
z = (np.sin(dx) + np.sin(dy))
z
Out[11]:
In [12]:
plt.imshow(z)
Out[12]:
In [13]:
plt.imshow(z)
plt.colorbar()
plt.title('Plot for sin(x) + sin(y)')
Out[13]:
In [14]:
A = np.array([1,2,3,4])
B = np.array([100,200,300,400])
In [15]:
condition = np.array([True, True, False, False])
In [18]:
answer = [(A_val if cond else B_val) for A_val, B_val, cond in zip(A, B, condition)]
In [19]:
answer
Out[19]:
In [20]:
answer2 = np.where(condition, A, B)
In [21]:
answer2
Out[21]:
In [22]:
from numpy.random import randn
arr = randn(5,5) arr
In [24]:
np.where(arr < 0, 0, arr)
Out[24]:
In [26]:
arr = np.array([[1,2,3], [4,5,6], [7,8,9]])
arr
Out[26]:
arr.sum()
In [27]:
arr.sum()
Out[27]:
In [28]:
arr.sum(0)
Out[28]:
In [29]:
arr.mean()
Out[29]:
In [30]:
arr.std()
Out[30]:
In [31]:
arr.var()
Out[31]:
In [32]:
bool_arr = np.array([True, False, True])
In [33]:
bool_arr.any()
Out[33]:
In [34]:
bool_arr.all()
Out[34]:
In [35]:
arr = randn(5)
In [36]:
arr
arr.sort()
arr
Out[36]:
In [38]:
countries = np.array(['France', 'Germany', 'USA', 'Russia', 'USA', 'Mexico'])
In [40]:
np.unique(countries)
Out[40]:
In [42]:
np.in1d(['France', 'USA', 'Sweeden'], countries)
Out[42]:
In [ ]: