SciPy有許多模塊、類和函數,io子模塊可用於從各種文件格式中讀取數據和將數據寫入各種文件格式。
from scipy import io
import numpy as np
生成數據
data = np.random.randint(0,100,size = (10,3))
保存數據:保存成mat格式的二進制文件
io.savemat("./data.mat",mdict = {"data":data})
加載數據
ret = io.loadmat("./data.mat")
讀取生成的數據
ret["data"]
顯示結果:
array([[90, 39, 31], [45, 8, 75], [75, 17, 5], [84, 62, 87], [30, 22, 32], [37, 15, 97], [67, 61, 95], [43, 13, 7], [27, 31, 40], [77, 25, 56]])
misc
是scipy中一個很雜的模塊
介紹對圖片進行過濾的方式
from scipy import misc
import matplotlib.pyplot as plt
%matplotlib inline
he = misc.imread("./timg1.jpg")
原圖:
import warnings
warnings.filterwarnings("ignore") #忽略警告問題
#imfilter中的一些屬性如下列表,
類似高斯濾波的卷積操作
array = [ 'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more','emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen']
he1 = misc.imfilter(he,array[0])
顯示第二個屬性樣式
plt.imshow(he1)