In [15]:
import scipy.misc
import matplotlib.pyplot as plt
%matplotlib inline
plt.gray()
img = scipy.misc.face().astype('float32')
plt.imshow(img)
img.dtype, img.shape, img.size
Out[15]:
In [9]:
import numpy
scores= numpy.array([101, 103,84],dtype='float32')
scores
Out[9]:
In [10]:
a=numpy.array(['Clesse', 'Idle', 'Gilliam'],dtype='str_')
a.dtype
Out[10]:
In [12]:
dt = numpy.dtype([('name',numpy.str_,16),('grades',numpy.float64,(2,))])
dt
Out[12]:
In [24]:
A=numpy.array([[1,2,3,4,5,6,7,8],[2,4,6,8,10,12,14,16]])
print (A)
print (A[0:2,0:8:2])
print(A[0:10,-1:0:-2])
print(A[:,::-2])
print(A[::-2])
print(A[[0,0,1,1],[0,3,2,5]]) # use the idx, must be same size
print(A[numpy.ix_([0,1],[0,3])])
In [16]:
value=0; import scipy.misc; img=scipy.misc.face()
for item in img.flat: value+=item
value
img.tofile("face.tx",sep=" ",format="%i")
print(img.min(), img.max(), img.ptp())
A=img.clip(img.min(),img.min()+100)
print(A.min(),A.max(),A.ptp())
plt.imshow(A)
Out[16]:
In [6]:
import numpy
A=numpy.array([11,13,15,17,19,18,16,14,12,10])
A.argsort(kind='mergesort')
A.sort()
print(A)
In [11]:
A=numpy.array([[1,1,1],[2,2,2],[3,3,3]])
print(A)
print(A.mean())
print(A.mean(axis=0))
print(A.mean(axis=1))
In [23]:
Z= numpy.zeros((5,5))
print(Z)
numpy.ones((5,5))
numpy.identity(3)
numpy.eye(4,k=1)
Out[23]:
In [29]:
B=numpy.fromfunction(( lambda i,j: i*j),(4,4))
print(B)
numpy.fromfunction(( lambda i,j: i*j),(4,4)) == 0
Out[29]:
In [32]:
numpy.where(B != 0)
numpy.putmask(B, B%2 != 0, B**2+1)
print(B)
In [36]:
L1 = numpy.arange(-1,1,0.3)
print(L1)
L2=numpy.linspace(-1,1,4)
print(L2)
L3=numpy.logspace(-1,1,4)
print(L3)
print(numpy.meshgrid(L2,L3))
In [38]:
print(numpy.mgrid[0:5,0:5])
print(numpy.ogrid[0:5,0:5])
In [45]:
B=numpy.ones((3,3))
checker2by2=numpy.zeros((6,6))
checker2by2[0:3,0:3] = checker2by2[3:6,3:6]=B
#numpy.tile(checker2by2,(4,4))
In [44]:
import scipy.ndimage
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
text = scipy.ndimage.imread('Chap_02_text_image.png')
In [ ]: