• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

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])
499128

src/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/p/y/pylon-HEAD/examples/pips/nlp.py   pylon(Download)
""" This example demonstrates how to use the Python Interior Point Solver using
the problem from http://en.wikipedia.org/wiki/Nonlinear_programming. """
 
from numpy import array, r_, float64, dot
from scipy.sparse import csr_matrix
from pips import pips
 
def gh2(x):
    h = dot(array([ [1, -1, 1], [1, 1, 1] ]), x**2) + array([-2.0, -10.0])
    dh = 2 * csr_matrix( array([ [x[0], x[0]], [-x[1], x[1]], [x[2], x[2]] ]) )
    g = array([])
    dg = None
    return h, g, dh, dg
 
def hess2(x, lam):
    mu = lam["ineqnonlin"]
    Lxx = csr_matrix( array([ r_[dot(2 * array([1, 1]), mu), -1, 0],
                              r_[-1, dot(2 * array([-1, 1]), mu), -1],
                              r_[0, -1, dot(2 * array([1, 1]), mu)] ]) )

src/b/i/biflib-HEAD/bal/python/examples/lyap.py   biflib(Download)
def gsr(x):
    from numpy import zeros, dot, sqrt
    from numpy.linalg import norm
    N = len(x)
    n = int(sqrt(N))
    znorm = zeros(n)
    znorm[0] = norm(x[0:n])
    xnorm = zeros(N)
    xnorm[0:n] = x[0:n] / znorm[0]
 
    for i in range(1,n):
        tmp = x[n*i:n*(i+1)].copy()
        for j in range(i):
            d = dot(x[n*i:n*(i+1)],xnorm[n*j:n*(j+1)])
        tmp = x[n*i:n*(i+1)].copy()
        for j in range(i):
            d = dot(x[n*i:n*(i+1)],xnorm[n*j:n*(j+1)])
            tmp = tmp - dot(x[n*i:n*(i+1)],xnorm[n*j:n*(j+1)])*xnorm[n*j:n*(j+1)]
        znorm[i] = norm(tmp)
        xnorm[n*i:n*(i+1)] = tmp / znorm[i]
    return xnorm,znorm

src/a/r/arboris-python-HEAD/examples/test_weight.py   arboris-python(Download)
from arboris.core import World, simulate
from pylab import plot, show, legend, xlabel, ylabel, title
from arboris.core import Observer
from numpy import arange, dot, eye, array
import arboris.homogeneousmatrix as homogeneousmatrix
from arboris.core import Body, SubFrame
from arboris.joints import FreeJoint
    def update(self, dt):
        self.timeline.append(self.world.current_time)
        self.height.append(dot(self.world.up, self.frame.pose[0:3,3]))
        print self.frame.pose[0:3,3]
 
    def finish(self):
        pass
    twist_c = array([0.,0.,0.,0.,0.,0.])
else:
    twist_c = array([1,1,1,0,0,0.])
twist_b = dot(homogeneousmatrix.adjoint(H_bc), twist_c)
freejoint = FreeJoint(gpos=homogeneousmatrix.inv(H_bc), gvel=twist_b)
w.add_link(w.ground, freejoint, body)
w.register(Box(subframe, half_extents))

src/o/p/openrave-HEAD/trunk/python/examples/tutorial_003.py   openrave(Download)
__copyright__ = '2010 Makoto Furukawa'
__license__ = 'Apache License, Version 2.0'
from openravepy import Environment, rotationMatrixFromAxisAngle, axisAngleFromRotationMatrix, matrixFromAxisAngle
from numpy import eye, dot, pi
 
def run(args=None):
    try:
            deg = -45
        rot_mat = rotationMatrixFromAxisAngle([1,0,0],float(deg)*pi/180.0)
        print 'AxisAngle = ',axisAngleFromRotationMatrix(rot_mat)
        tran[0:3,0:3] = dot(rot_mat, tran[0:3,0:3])
        body.SetTransform(tran)
 
        P1 = dot(rot_mat, [0,0,1])
            deg = 45
        rot_mat = rotationMatrixFromAxisAngle([0,1,0],float(deg)*pi/180.0)
        print 'AxisAngle = ',axisAngleFromRotationMatrix(rot_mat)
        tran[0:3,0:3] = dot(rot_mat, tran[0:3,0:3])
        body.SetTransform(tran)
 
        P2 = dot(rot_mat, P1)
        handles.append(env.drawarrow([0.0,0.0,0.0],P2,linewidth=0.01,color=[1.0,1.0,0.0]))
 
        while True:
            raw_input('キーを押すと回転しながら移動します.')
            Tdelta = matrixFromAxisAngle ([0,0,0.5])
            Tdelta[2,3] = 0.01
            tran = dot(tran, Tdelta)

src/s/l/Slycot-HEAD/slycot/examples.py   Slycot(Download)
def sb02od_example():
	from numpy import zeros, shape, dot, ones
	A = array([ [0, 1],
				[0, 0]])
	B = array([ [0],
				[1]])
	C = array([ [1, 0],
				[0, 1],
				[0, 0]])
	Q = dot(C.T,C)

src/o/p/openrave-HEAD/python/examples/tutorial_003.py   openrave(Download)
__copyright__ = '2010 Makoto Furukawa'
__license__ = 'Apache License, Version 2.0'
from openravepy import Environment, rotationMatrixFromAxisAngle, axisAngleFromRotationMatrix, matrixFromAxisAngle
from numpy import eye, dot, pi
 
def run(args=None):
    try:
            deg = -45
        rot_mat = rotationMatrixFromAxisAngle([1,0,0],float(deg)*pi/180.0)
        print 'AxisAngle = ',axisAngleFromRotationMatrix(rot_mat)
        tran[0:3,0:3] = dot(rot_mat, tran[0:3,0:3])
        body.SetTransform(tran)
 
        P1 = dot(rot_mat, [0,0,1])
            deg = 45
        rot_mat = rotationMatrixFromAxisAngle([0,1,0],float(deg)*pi/180.0)
        print 'AxisAngle = ',axisAngleFromRotationMatrix(rot_mat)
        tran[0:3,0:3] = dot(rot_mat, tran[0:3,0:3])
        body.SetTransform(tran)
 
        P2 = dot(rot_mat, P1)
        handles.append(env.drawarrow([0.0,0.0,0.0],P2,linewidth=0.01,color=[1.0,1.0,0.0]))
 
        while True:
            raw_input('キーを押すと回転しながら移動します.')
            Tdelta = matrixFromAxisAngle ([0,0,0.5])
            Tdelta[2,3] = 0.01
            tran = dot(tran, Tdelta)

src/c/s/csc-pysparse-HEAD/examples/jdsym_test.py   csc-pysparse(Download)
from pysparse import spmatrix, jdsym, itsolvers
from numpy import zeros, dot, allclose, multiply
from math import sqrt
import RandomArray
 
class diagPrecShifted:
    def __init__(self, A, M, sigma):
        else:
            t = u
        r = r - lmbd[k]*t
        residuals[k] = sqrt(dot(r,r))
    return residuals
 
n = 1000; ncv = 5; tol = 1e-6

src/p/y/pysparse-HEAD/trunk/examples/jdsym_test.py   pysparse(Download)
from pysparse.sparse import spmatrix
from pysparse.eigen import jdsym
from pysparse.itsolvers.krylov import qmrs
from numpy import zeros, dot, allclose, multiply, random
from math import sqrt
 
class diagPrecShifted:
        else:
            t = u
        r = r - lmbd[k]*t
        residuals[k] = sqrt(dot(r,r))
    return residuals
 
n = 1000; ncv = 5; tol = 1e-6

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next