本文整理汇总了Python中scipy.fftpack.diff函数的典型用法代码示例。如果您正苦于以下问题:Python diff函数的具体用法?Python diff怎么用?Python diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了diff函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: bench_random
def bench_random(self):
print()
print('Differentiation of periodic functions')
print('=====================================')
print(' size | convolve | naive')
print('-------------------------------------')
for size,repeat in [(100,1500),(1000,300),
(256,1500),
(512,1000),
(1024,500),
(2048,200),
(2048*2,100),
(2048*4,50),
]:
print('%6s' % size, end=' ')
sys.stdout.flush()
x = arange(size)*2*pi/size
if size < 2000:
f = sin(x)*cos(4*x)+exp(sin(3*x))
else:
f = sin(x)*cos(4*x)
assert_array_almost_equal(diff(f,1),direct_diff(f,1))
assert_array_almost_equal(diff(f,2),direct_diff(f,2))
print('| %9.2f' % measure('diff(f,3)',repeat), end=' ')
sys.stdout.flush()
print('| %9.2f' % measure('direct_diff(f,3)',repeat), end=' ')
sys.stdout.flush()
print(' (secs for %s calls)' % (repeat))
开发者ID:ChadFulton,项目名称:scipy,代码行数:28,代码来源:bench_pseudo_diffs.py
示例2: test_period
def test_period(self):
for n in [17,64]:
x = arange(n)/float(n)
assert_array_almost_equal(diff(sin(2*pi*x),period=1),
2*pi*cos(2*pi*x))
assert_array_almost_equal(diff(sin(2*pi*x),3,period=1),
-(2*pi)**3*cos(2*pi*x))
开发者ID:BranYang,项目名称:scipy,代码行数:7,代码来源:test_pseudo_diffs.py
示例3: test_int
def test_int(self):
n = 64
x = arange(n)*2*pi/n
assert_array_almost_equal(diff(sin(x),-1),-cos(x))
assert_array_almost_equal(diff(sin(x),-2),-sin(x))
assert_array_almost_equal(diff(sin(x),-4),sin(x))
assert_array_almost_equal(diff(2*cos(2*x),-1),sin(2*x))
开发者ID:BranYang,项目名称:scipy,代码行数:7,代码来源:test_pseudo_diffs.py
示例4: test_random_odd
def test_random_odd(self):
for k in [0,1,2,3,4,5,6]:
for n in [33,65,55]:
f = random((n,))
af = sum(f,axis=0)/n
f = f-af
assert_almost_equal(sum(f,axis=0),0.0)
assert_array_almost_equal(diff(diff(f,k),-k),f)
assert_array_almost_equal(diff(diff(f,-k),k),f)
开发者ID:BranYang,项目名称:scipy,代码行数:9,代码来源:test_pseudo_diffs.py
示例5: test_random_even
def test_random_even(self):
for n in [32,64,56]:
f = random((n,))
af = sum(f,axis=0)/n
f = f-af
# zeroing Nyquist mode:
f = diff(diff(f,1),-1)
assert_almost_equal(sum(f,axis=0),0.0)
assert_array_almost_equal(direct_hilbert(direct_ihilbert(f)),f)
assert_array_almost_equal(hilbert(ihilbert(f)),f)
开发者ID:BranYang,项目名称:scipy,代码行数:10,代码来源:test_pseudo_diffs.py
示例6: test_expr_large
def test_expr_large(self):
for n in [2048,4096]:
x = arange(n)*2*pi/n
f = sin(x)*cos(4*x)+exp(sin(3*x))
df = cos(x)*cos(4*x)-4*sin(x)*sin(4*x)+3*cos(3*x)*exp(sin(3*x))
ddf = -17*sin(x)*cos(4*x)-8*cos(x)*sin(4*x)\
- 9*sin(3*x)*exp(sin(3*x))+9*cos(3*x)**2*exp(sin(3*x))
assert_array_almost_equal(diff(f),df)
assert_array_almost_equal(diff(df),ddf)
assert_array_almost_equal(diff(ddf,-1),df)
assert_array_almost_equal(diff(f,2),ddf)
开发者ID:BranYang,项目名称:scipy,代码行数:11,代码来源:test_pseudo_diffs.py
示例7: test_expr
def test_expr(self):
for n in [64,77,100,128,256,512,1024,2048,4096,8192][:5]:
x = arange(n)*2*pi/n
f = sin(x)*cos(4*x)+exp(sin(3*x))
df = cos(x)*cos(4*x)-4*sin(x)*sin(4*x)+3*cos(3*x)*exp(sin(3*x))
ddf = -17*sin(x)*cos(4*x)-8*cos(x)*sin(4*x)\
- 9*sin(3*x)*exp(sin(3*x))+9*cos(3*x)**2*exp(sin(3*x))
d1 = diff(f)
assert_array_almost_equal(d1,df)
assert_array_almost_equal(diff(df),ddf)
assert_array_almost_equal(diff(f,2),ddf)
assert_array_almost_equal(diff(ddf,-1),df)
开发者ID:BranYang,项目名称:scipy,代码行数:12,代码来源:test_pseudo_diffs.py
示例8: find_peaks
def find_peaks(signal, v_mph, v_mpd, v_cutMin, v_cutMax):
#signal[-100:100] = 0.0
foierSignal = filterFourier(signal, v_cutMin, v_cutMax)
diffFoierSignal = diff(foierSignal,1)
dev_flag=True
if (dev_flag == True):
import matplotlib.pyplot as plt
from random import randint
plt.figure()
plt.plot(np.linspace(100, len(signal)-100, num=len(signal.real[100:-100])), 40*signal.real[100:-100], '-r')
plt.plot(np.linspace(100, len(diffFoierSignal)-100, num=len(diffFoierSignal.real[100:-100])), -diffFoierSignal.real[100:-100], '-g')
plt.savefig('test/%sdifStress.png'%( randint(0,99) ), dpi=150)
from detect_peaks import detect_peaks
ind = detect_peaks(-diffFoierSignal.real[150:-150], mph=v_mph, mpd=v_mpd, show=False)
vmax = []
vmin = []
id_vmax = []
id_vmin = []
i = 0
d_find = 50
while i < len(ind):
s = signal
if (len(ind) != 0 ):
if ( np.fabs(len(s)-ind[i]) > d_find and ind[i] > d_find ):
vmax.append(max( s[ ind[i] - d_find : ind[i] + d_find] ) )
id_vmax.append([k for k, j in enumerate(s[ind[i]-d_find:ind[i]+d_find]) if j == vmax[i]][0] + ind[i] - d_find)
else:
vmax.append(max( s[ ind[i] - d_find : ind[i]] ) )
id_vmax.append([k for k, j in enumerate(s[ind[i]-d_find:ind[i]]) if j == vmax[i]][0] + ind[i]-d_find)
if ( np.fabs(len(s)-ind[i]) > d_find and ind[i] > d_find ):
vmin.append(min( s[ ind[i] - d_find : ind[i] + d_find] ) )
id_vmin.append([k for k, j in enumerate(s[ind[i] - d_find : ind[i] + d_find]) if j == vmin[i]][0]+ind[i]-d_find)
else:
vmin.append(min( s[ ind[i] : ind[i] + d_find] ) )
id_vmin.append([k for k, j in enumerate(s[ ind[i] : ind[i] + d_find ] ) if j == vmin[i]][0]+ind[i]-d_find)
i += 1
return [id_vmax,vmax,id_vmin,vmin]
开发者ID:zhekan,项目名称:MDrun,代码行数:49,代码来源:stress_analis.py
示例9: test_sin
def test_sin(self):
for n in [32,64,77]:
x = arange(n)*2*pi/n
assert_array_almost_equal(diff(sin(x)),cos(x))
assert_array_almost_equal(diff(cos(x)),-sin(x))
assert_array_almost_equal(diff(sin(x),2),-sin(x))
assert_array_almost_equal(diff(sin(x),4),sin(x))
assert_array_almost_equal(diff(sin(4*x)),4*cos(4*x))
assert_array_almost_equal(diff(sin(sin(x))),cos(x)*cos(sin(x)))
开发者ID:BranYang,项目名称:scipy,代码行数:9,代码来源:test_pseudo_diffs.py
示例10: test_zero_nyquist
def test_zero_nyquist(self):
for k in [0,1,2,3,4,5,6]:
for n in [32,33,64,56,55]:
f = random((n,))
af = sum(f,axis=0)/n
f = f-af
# zeroing Nyquist mode:
f = diff(diff(f,1),-1)
assert_almost_equal(sum(f,axis=0),0.0)
assert_array_almost_equal(diff(diff(f,k),-k),f)
assert_array_almost_equal(diff(diff(f,-k),k),f)
开发者ID:BranYang,项目名称:scipy,代码行数:11,代码来源:test_pseudo_diffs.py
示例11: time_diff
def time_diff(self, size, soltype):
if soltype == 'fft':
diff(self.f, 3)
else:
direct_diff(self.f, 3)
开发者ID:1641731459,项目名称:scipy,代码行数:5,代码来源:fftpack_pseudo_diffs.py
示例12: test_definition
def test_definition(self):
for n in [16,17,64,127,32]:
x = arange(n)*2*pi/n
assert_array_almost_equal(diff(sin(x)),direct_diff(sin(x)))
assert_array_almost_equal(diff(sin(x),2),direct_diff(sin(x),2))
assert_array_almost_equal(diff(sin(x),3),direct_diff(sin(x),3))
assert_array_almost_equal(diff(sin(x),4),direct_diff(sin(x),4))
assert_array_almost_equal(diff(sin(x),5),direct_diff(sin(x),5))
assert_array_almost_equal(diff(sin(2*x),3),direct_diff(sin(2*x),3))
assert_array_almost_equal(diff(sin(2*x),4),direct_diff(sin(2*x),4))
assert_array_almost_equal(diff(cos(x)),direct_diff(cos(x)))
assert_array_almost_equal(diff(cos(x),2),direct_diff(cos(x),2))
assert_array_almost_equal(diff(cos(x),3),direct_diff(cos(x),3))
assert_array_almost_equal(diff(cos(x),4),direct_diff(cos(x),4))
assert_array_almost_equal(diff(cos(2*x)),direct_diff(cos(2*x)))
assert_array_almost_equal(diff(sin(x*n/8)),direct_diff(sin(x*n/8)))
assert_array_almost_equal(diff(cos(x*n/8)),direct_diff(cos(x*n/8)))
for k in range(5):
assert_array_almost_equal(diff(sin(4*x),k),direct_diff(sin(4*x),k))
assert_array_almost_equal(diff(cos(4*x),k),direct_diff(cos(4*x),k))
开发者ID:BranYang,项目名称:scipy,代码行数:20,代码来源:test_pseudo_diffs.py
示例13: print
# CsPbI3 - distorted
PB_X=0.469972*NGX
PB_Y=0.530081*NGY
PB_Z=0.468559*NGZ
# CsPbI3 - perfect cubic
#PB_X=0.5*NGX
#PB_Y=0.5*NGY
#PB_Z=0.5*NGZ
# MAPBI3 - pseudo cubic distorted
#PB_X=0.476171*NGX
#PB_Y=0.500031*NGY
#PB_Z=0.475647*NGZ
# Read out massive grad table, in {x,y,z} components
print(grad_x[PB_X][PB_Y][PB_Z],grad_y[PB_X][PB_Y][PB_Z],grad_z[PB_X][PB_Y][PB_Z])
# Norm of electric field at this point
print(np.linalg.norm([ grad_x[PB_X][PB_Y][PB_Z],grad_y[PB_X][PB_Y][PB_Z],grad_z[PB_X][PB_Y][PB_Z] ]))
# OK, let's try this with a Spectral method (FFT)
# JMF - Not currently working; unsure of data formats, need worked example
from scipy import fftpack
V_FFT=fftpack.fftn(grid_pot[:,:,:])
V_deriv=fftpack.diff(grid_pot[:,:,:]) #V_FFT,order=1)
# Standard catch all to drop into ipython at end of script for variable inspection etc.
from IPython import embed; embed() # End on an interactive ipython console to inspect variables etc.
开发者ID:Yvetteoo,项目名称:MacroDensity,代码行数:28,代码来源:FieldAtPoint.py
注:本文中的scipy.fftpack.diff函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论