All Samples(7296) | Call(6860) | Derive(0) | Import(436)
dot(a, b)
Dot product of two arrays.
For 2-D arrays it is equivalent to matrix multiplication, and for 1-D
arrays to inner product of vectors (without complex conjugation). For
N dimensions it is a sum product over the last axis of `a` and
the second-to-last of `b`::
dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
Parameters
----------
a : array_like
First argument.
b : array_like
Second argument.
Returns
-------
output : ndarray
Returns the dot product of `a` and `b`. If `a` and `b` are both
scalars or both 1-D arrays then a scalar is returned; otherwise
an array is returned.
Raises
------
ValueError
If the last dimension of `a` is not the same size as
the second-to-last dimension of `b`.
See Also
--------
vdot : Complex-conjugating dot product.
tensordot : Sum products over arbitrary axes.
Examples
--------
>>> np.dot(3, 4)
12
Neither argument is complex-conjugated:
>>> np.dot([2j, 3j], [2j, 3j])
(-13+0j)
For 2-D arrays it's the matrix product:
>>> a = [[1, 0], [0, 1]]
>>> b = [[4, 1], [2, 2]]
>>> np.dot(a, b)
array([[4, 1],
[2, 2]])
>>> a = np.arange(3*4*5*6).reshape((3,4,5,6))
>>> b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3))
>>> np.dot(a, b)[2,3,2,1,2,2]
499128
>>> sum(a[2,3,2,:] * b[1,2,:,2])
499128src/o/p/openrave-HEAD/trunk/python/examples/hanoi.py openrave(Download)
from openravepy import Environment, IkParameterization, planning_error, raveLogInfo, raveLogWarn, OpenRAVEGlobalArguments, RaveDestroy from openravepy.interfaces import BaseManipulation, TaskManipulation from openravepy.databases import inversekinematics from numpy import array, arange, linalg, pi, dot, vstack, cos, sin, cross, r_, c_ from optparse import OptionParser class HanoiPuzzle:
Tpeg = destpeg.GetTransform()
src_upvec = Tsrcpeg[0:3,2:3]
dest_upvec = Tpeg[0:3,2:3]
Tdiff = dot(linalg.inv(Tdisk), Thand)
# iterate across all possible orientations the destination peg can be in
for ang in arange(-pi,pi,0.3):
# find the dest position
p = Tpeg[0:3,3:4] + height * dest_upvec
R = dot(Tpeg[0:3,0:3], array(((cos(ang),-sin(ang),0),(sin(ang),cos(ang),0),(0,0,1))))
T = dot(r_[c_[R,p], [[0,0,0,1]]], Tdiff)
def GetGrasp(self, Tdisk, radius, angles):
""" returns the transform of the grasp given its orientation and the location/size of the disk"""
zdir = -dot(Tdisk[0:3,0:3],vstack([cos(angles[0])*cos(angles[1]),-cos(angles[0])*sin(angles[1]),-sin(angles[0])]))
pos = Tdisk[0:3,3:4] + radius*dot(Tdisk[0:3,0:3],vstack([cos(angles[1]),-sin(angles[1]),0]))
xdir = cross(Tdisk[0:3,1:2],zdir,axis=0)
xdir = xdir / linalg.norm(xdir)
ydir = cross(zdir,xdir,axis=0)
Tgrasp = r_[c_[xdir,ydir,zdir,pos],[[0,0,0,1]]]
return [Tgrasp,dot(Tgrasp, array([[-1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]]))]
src/o/p/openrave-HEAD/python/examples/hanoi.py openrave(Download)
from openravepy import Environment, IkParameterization, planning_error, raveLogInfo, raveLogWarn, OpenRAVEGlobalArguments from openravepy.interfaces import BaseManipulation, TaskManipulation from openravepy.databases import inversekinematics from numpy import array, arange, linalg, pi, dot, vstack, cos, sin, cross, r_, c_ from optparse import OptionParser class HanoiPuzzle:
Tpeg = destpeg.GetTransform()
src_upvec = Tsrcpeg[0:3,2:3]
dest_upvec = Tpeg[0:3,2:3]
Tdiff = dot(linalg.inv(Tdisk), Thand)
# iterate across all possible orientations the destination peg can be in
for ang in arange(-pi,pi,0.3):
# find the dest position
p = Tpeg[0:3,3:4] + height * dest_upvec
R = dot(Tpeg[0:3,0:3], array(((cos(ang),-sin(ang),0),(sin(ang),cos(ang),0),(0,0,1))))
T = dot(r_[c_[R,p], [[0,0,0,1]]], Tdiff)
def GetGrasp(self, Tdisk, radius, angles):
""" returns the transform of the grasp given its orientation and the location/size of the disk"""
zdir = -dot(Tdisk[0:3,0:3],vstack([cos(angles[0])*cos(angles[1]),-cos(angles[0])*sin(angles[1]),-sin(angles[0])]))
pos = Tdisk[0:3,3:4] + radius*dot(Tdisk[0:3,0:3],vstack([cos(angles[1]),-sin(angles[1]),0]))
xdir = cross(Tdisk[0:3,1:2],zdir,axis=0)
xdir = xdir / linalg.norm(xdir)
ydir = cross(zdir,xdir,axis=0)
Tgrasp = r_[c_[xdir,ydir,zdir,pos],[[0,0,0,1]]]
return [Tgrasp,dot(Tgrasp, array([[-1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]]))]
src/n/i/nipy-HEAD/examples/neurospin/need_data/example_roi_and_glm.py nipy(Download)
# fitted and adjusted response ######################################## res = ROI_tc -np.dot(glm.beta.T, X.T) proj = np.eye(nreg) proj[2:] = 0 fit = np.dot(np.dot(glm.beta.T,proj),X.T)
src/n/i/nipy-HEAD/nipy/algorithms/tests/test_resample.py nipy(Download)
def mapper(x):
return np.dot(x, A.T) + b
ir = resample(i, i.coordmap, mapper, (100,90))
yield assert_array_almost_equal, ir[42:47,32:47], 3.
def test_resample2d2():
src/n/i/NiPy-OLD-HEAD/nipy/algorithms/tests/test_resample.py NiPy-OLD(Download)
def mapper(x):
return np.dot(x, A.T) + b
ir = resample(i, i.coordmap, mapper, (100,90))
yield assert_array_almost_equal, ir[42:47,32:47], 3.
def test_resample2d2():
src/s/c/scikits.statsmodels-0.2.0/scikits/statsmodels/sandbox/tsa/example_arma.py scikits.statsmodels(Download)
def acovf_explicit(ar, ma, nobs):
'''add correlation of MA representation explicitely
'''
ir = arma_impulse_response(ar, ma)
acovfexpl = [np.dot(ir[:nobs-t], ir[t:nobs]) for t in range(10)]
return acovfexpl
u = np.zeros(N)
P = len(taps)
for l in xrange(P):
u[l] = v[l] + np.dot(u[:l][::-1], taps[:l])
for l in xrange(P,N):
u[l] = v[l] + np.dot(u[l-P:l][::-1], taps)
return u, v, taps
c = np.correlate(x, y, mode=2)
if normed: c/= np.sqrt(np.dot(x,x) * np.dot(y,y))
if maxlags is None: maxlags = Nx - 1
src/s/c/scikits.statsmodels-0.2.0/scikits/statsmodels/examples/example_glsar.py scikits.statsmodels(Download)
noise = signal.lfilter([1], np.hstack((1,-rhotrue)), wnoise)[nlags:]
# generate GLS model with AR noise
y1 = np.dot(X1,beta) + noise
if 1 in examples:
print '\nExample 1: iterative_fit and repeated calls'
src/n/i/NiPy-OLD-HEAD/examples/neurospin/need_data/group_reproducibility_analysis.py NiPy-OLD(Download)
affine = rbeta.get_affine() coord = np.hstack((xyz, np.ones((nvox, 1)))) coord = np.dot(coord, affine.T)[:,:3] ################################################################################ # script
src/s/c/scikits.statsmodels-0.2.0/scikits/statsmodels/examples/example_ols_tftest.py scikits.statsmodels(Download)
dummyvar = (xcat == np.arange(ncat)).astype(float) beta = np.array([0., 2, -2, 1])[:,np.newaxis] ytrue = np.dot(dummyvar, beta) X = sm.tools.add_constant(dummyvar[:,:-1]) y = ytrue + sigma * np.random.randn(nsample,1) mod2 = sm.OLS(y[:,0], X)
R5 = np.atleast_2d([0, 1, 1, 2]) np.dot(R5,res2.params) Ftest = res2.f_test(R5) print repr((Ftest.fvalue, Ftest.pvalue)) ttest = res2.t_test(R5) #print repr((ttest.t, ttest.pvalue)) print repr((ttest.tvalue, ttest.pvalue)) R6 = np.atleast_2d([1, -1, 0, 0]) np.dot(R6,res2.params)
print repr((ttest.tvalue, ttest.pvalue)) R7 = np.atleast_2d([1, 0, 0, 0]) np.dot(R7,res2.params) Ftest = res2.f_test(R7) print repr((Ftest.fvalue, Ftest.pvalue)) ttest = res2.t_test(R7)
res2 = mod2.fit() R8 = np.atleast_2d([1, 0]) np.dot(R8,res2.params) Ftest = res2.f_test(R8) print repr((Ftest.fvalue, Ftest.pvalue)) print repr((np.sqrt(Ftest.fvalue), Ftest.pvalue))
src/n/i/nipy-HEAD/examples/formula/parametric_design.py nipy(Download)
v2 = np.sum([-3.5*a*hrf.glovert(tt - s)*np.exp(-4.5*a) for s,a in zip(t, dt)], 0) V = np.array([v1,v2]).T W = V - np.dot(X3, np.dot(np.linalg.pinv(X3), V)) niptest.assert_almost_equal((W**2).sum() / (V**2).sum(), 0)
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next