python_数据_scipy_积分&misc

积分 integrate

start

import numpy as np
import pandas as pd
from scipy import integrate
import matplotlib.pyplot as plt

使用积分计算圆周率

x = np.linspace(-1,1,100)
circle = lambda x : (1 - x ** 2) ** 0.5
plt.figure(figsize=(5,5))
plt.plot(x,circle(x))
plt.plot(x,-circle(x))
ret,error = integrate.quad(circle,a=-1,b=1)   # (积分结果,误差)
  • 参数一为需要积分的函数,a,b为积分区间
  • 返回值一为积分结果,二为积分误差
print('pi:',ret * 2)
  • out: pi: 3.141592653589797

misc

from scipy import io
from scipy import misc
data = np.random.randint(0,150,size=(150,3))
io.savemat('./data.mat',mdict={
    'data':data,
})  # mat 是一个标准的二进制文件
ret = io.loadmat('./data.mat')
ret
  • out:{‘header’: b’MATLAB 5.0 MAT-file Platform: nt, Created on: Mon Jan 14 14:20:01 2019’,
    version’: ‘1.0’,
    globals’: [],
    ‘data’: array([[ 69, 128, 22],
    [ 96, 142, 43],
    [ 53, 29, 28],
    [ 6, 135, 138],
    [ 5, 79, 96],
    [104, 64, 133],
cat = misc.imread('./cat.jpg')

在这里插入图片描述

plt.imshow(misc.imrotate(cat,60))
  • 注意:与ndimage的rotate方法不同的是,此时,图片旋转后,超出原图片范围的部分会隐藏

imrotate is deprecated!
imrotate is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use skimage.transform.rotate instead.

plt.imshow(misc.imresize(cat,60))    # 60%
  • 改变图片的大小

imresize is deprecated!
imresize is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use skimage.transform.resize instead.

plt.imshow(misc.imfilter(cat,ftype='emboss'))    # 
'''ftype : str
        The filter that has to be applied. Legal values are:
        'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more',
        'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'.'''
  • out : 实现艺术效果----石雕
  • 据说是通过卷积实现的

imfilter is deprecated!
imfilter is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use Pillow filtering functionality directly.

猜你喜欢

转载自blog.csdn.net/sinat_39045958/article/details/86530831