本文整理匯總了Python中numpy.i0方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.i0方法的具體用法?Python numpy.i0怎麽用?Python numpy.i0使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.i0方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: execute
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import i0 [as 別名]
def execute(cls, ctx, op):
x = ctx[op.inputs[0].key]
xp = get_array_module(x)
res = xp.i0(x)
if not is_sparse_module(xp):
res = res.reshape(op.outputs[0].shape)
ctx[op.outputs[0].key] = res
示例2: test_i0
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import i0 [as 別名]
def test_i0(self):
q = np.array([0., 10., 20.]) * u.percent
out = np.i0(q)
expected = np.i0(q.to_value(u.one)) * u.one
assert isinstance(out, u.Quantity)
assert np.all(out == expected)
with pytest.raises(u.UnitsError):
np.i0(self.q)
示例3: i0
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import i0 [as 別名]
def i0(x, **kwargs):
"""
Modified Bessel function of the first kind, order 0.
Usually denoted :math:`I_0`. This function does broadcast, but will *not*
"up-cast" int dtype arguments unless accompanied by at least one float or
complex dtype argument (see Raises below).
Parameters
----------
x : array_like, dtype float or complex
Argument of the Bessel function.
Returns
-------
out : Tensor, shape = x.shape, dtype = x.dtype
The modified Bessel function evaluated at each of the elements of `x`.
Raises
------
TypeError: array cannot be safely cast to required type
If argument consists exclusively of int dtypes.
See Also
--------
scipy.special.iv, scipy.special.ive
Notes
-----
We use the algorithm published by Clenshaw [1]_ and referenced by
Abramowitz and Stegun [2]_, for which the function domain is
partitioned into the two intervals [0,8] and (8,inf), and Chebyshev
polynomial expansions are employed in each interval. Relative error on
the domain [0,30] using IEEE arithmetic is documented [3]_ as having a
peak of 5.8e-16 with an rms of 1.4e-16 (n = 30000).
References
----------
.. [1] C. W. Clenshaw, "Chebyshev series for mathematical functions", in
*National Physical Laboratory Mathematical Tables*, vol. 5, London:
Her Majesty's Stationery Office, 1962.
.. [2] M. Abramowitz and I. A. Stegun, *Handbook of Mathematical
Functions*, 10th printing, New York: Dover, 1964, pp. 379.
http://www.math.sfu.ca/~cbm/aands/page_379.htm
.. [3] http://kobesearch.cpan.org/htdocs/Math-Cephes/Math/Cephes.html
Examples
--------
>>> import mars.tensor as mt
>>> mt.i0([0.]).execute()
array([1.])
>>> mt.i0([0., 1. + 2j]).execute()
array([ 1.00000000+0.j , 0.18785373+0.64616944j])
"""
op = TensorI0(**kwargs)
return op(x)
示例4: sample
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import i0 [as 別名]
def sample(self):
if self.tr_cond == 'all_gains':
G = (1.0/self.stim_dur) * np.random.choice([1.0], size=(self.n_loc,self.batch_size))
G = np.repeat(G,self.n_in,axis=0).T
G = np.tile(G,(self.stim_dur,1,1))
G = np.swapaxes(G,0,1)
else:
G = (0.5/self.stim_dur) * np.random.choice([1.0], size=(1,self.batch_size))
G = np.repeat(G,self.n_in * self.n_loc, axis=0).T
G = np.tile(G,(self.stim_dur,1,1))
G = np.swapaxes(G,0,1)
H = (1.0/self.resp_dur) * np.ones((self.batch_size,self.resp_dur,self.nneuron))
# Target presence/absence and stimuli
C = np.random.choice([0.0, 1.0], size=(self.batch_size,))
C1ind = np.where(C==1.0)[0] # change
S1 = np.pi * np.random.rand(self.n_loc, self.batch_size)
S2 = S1.copy()
S1 = np.repeat(S1,self.n_in,axis=0).T
S1 = np.tile(S1,(self.stim_dur,1,1))
S1 = np.swapaxes(S1,0,1)
S2[np.random.randint(0,self.n_loc,size=(len(C1ind),)), C1ind] = np.pi * np.random.rand(len(C1ind))
S2 = np.repeat(S2,self.n_in,axis=0).T
S2 = np.tile(S2,(self.resp_dur,1,1))
S2 = np.swapaxes(S2,0,1)
# Noisy responses
L1 = G * np.exp( self.kappa * (np.cos( 2.0 * (S1 - np.tile(self.phi, (self.batch_size,self.stim_dur,self.n_loc) ) ) ) - 1.0) ) # stim 1
L2 = H * np.exp( self.kappa * (np.cos( 2.0 * (S2 - np.tile(self.phi, (self.batch_size,self.resp_dur,self.n_loc) ) ) ) - 1.0) ) # stim 2
Ld = (self.spon_rate / self.delay_dur) * np.ones((self.batch_size,self.delay_dur,self.nneuron)) # delay
R1 = np.random.poisson(L1)
R2 = np.random.poisson(L2)
Rd = np.random.poisson(Ld)
example_input = np.concatenate((R1,Rd,R2), axis=1)
example_output = np.repeat(C[:,np.newaxis],self.total_dur,axis=1)
example_output = np.repeat(example_output[:,:,np.newaxis],1,axis=2)
cum_R1 = np.sum(R1,axis=1)
cum_R2 = np.sum(R2,axis=1)
mu_x = np.asarray([ np.arctan2( np.dot(cum_R1[:,i*self.n_in:(i+1)*self.n_in],np.sin(2.0*self.phi)), np.dot(cum_R1[:,i*self.n_in:(i+1)*self.n_in],np.cos(2.0*self.phi))) for i in range(self.n_loc) ])
mu_y = np.asarray([ np.arctan2( np.dot(cum_R2[:,i*self.n_in:(i+1)*self.n_in],np.sin(2.0*self.phi)), np.dot(cum_R2[:,i*self.n_in:(i+1)*self.n_in],np.cos(2.0*self.phi))) for i in range(self.n_loc) ])
temp_x = np.asarray([np.swapaxes(np.multiply.outer(cum_R1,cum_R1),1,2)[i,i,:,:] for i in range(self.batch_size)])
temp_y = np.asarray([np.swapaxes(np.multiply.outer(cum_R2,cum_R2),1,2)[i,i,:,:] for i in range(self.batch_size)])
kappa_x = np.asarray( [np.sqrt(np.sum(temp_x[:,i*self.n_in:(i+1)*self.n_in,i*self.n_in:(i+1)*self.n_in] * np.repeat(np.cos( np.subtract(np.expand_dims(self.phi,axis=1), np.expand_dims(self.phi,axis=1).T) )[np.newaxis,:,:],self.batch_size,axis=0),axis=(1,2))) for i in range(self.n_loc) ] )
kappa_y = np.asarray( [np.sqrt(np.sum(temp_y[:,i*self.n_in:(i+1)*self.n_in,i*self.n_in:(i+1)*self.n_in] * np.repeat(np.cos( np.subtract(np.expand_dims(self.phi,axis=1), np.expand_dims(self.phi,axis=1).T) )[np.newaxis,:,:],self.batch_size,axis=0),axis=(1,2))) for i in range(self.n_loc) ] )
if self.n_loc==1:
d = np.i0(kappa_x) * np.i0(kappa_y) / np.i0( np.sqrt(kappa_x ** 2 + kappa_y ** 2 + 2.0 * kappa_x * kappa_y * np.cos(mu_y-mu_x)) )
else:
d = np.nanmean(np.i0(kappa_x) * np.i0(kappa_y) / np.i0( np.sqrt(kappa_x ** 2 + kappa_y ** 2 + 2.0 * kappa_x * kappa_y * np.cos(mu_y-mu_x)) ), axis=0)
P = d / (d + 1.0)
return example_input, example_output, C, P