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

All Samples(2491)  |  Call(2246)  |  Derive(0)  |  Import(245)
cos(x[, out])

Cosine elementwise.

Parameters
----------
x : array_like
    Input array in radians.
out : ndarray, optional
    Output array of same shape as `x`.

Returns
-------
y : ndarray
    The corresponding cosine values.

Raises
------
ValueError: invalid return array shape
    if `out` is provided and `out.shape` != `x.shape` (See Examples)

Notes
-----
If `out` is provided, the function writes the result into it,
and returns a reference to `out`.  (See Examples)

References
----------
M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions.
New York, NY: Dover, 1972.

Examples
--------
>>> np.cos(np.array([0, np.pi/2, np.pi]))
array([  1.00000000e+00,   6.12303177e-17,  -1.00000000e+00])
>>>
>>> # Example of providing the optional output parameter
>>> out2 = np.cos([0.1], out1)
>>> out2 is out1
True
>>>
>>> # Example of ValueError due to provision of shape mis-matched `out`
>>> np.cos(np.zeros((3,3)),np.zeros((2,2)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid return array shape

src/m/a/matplotlib-HEAD/py4science/examples/numpytemps.py   matplotlib(Download)
import nose
 
# convenience global names
from numpy import (pi, sin, cos, add, subtract, multiply, power)
 
def test1():
    """Verify an expression using temporaries.
    # 4.5*cos(3*x**2): 4
    # The final temporaries for each term are added and the result stored as y,
    # which is also created.  So we have 1 array for the result and 7 temps.
    y = sin(x) + sin(2*x) - 4.5*cos(3*x**2)
 
    # Now we do it again, but here, we control the temporary creation
    # ourselves.  We use the output argument of all numpy functional forms of
    # - 4.5*cos(3*x**2)
    power(x,2,tmp)
    multiply(3,tmp,tmp)
    cos(tmp,tmp)
    multiply(4.5,tmp,tmp)
    subtract(z,tmp,z)
 
def test2():
    """Compute the same expression, using in-place operations
    """
    x = np.linspace(0,2*pi,100)
 
    y = sin(x) + sin(2*x) - 4.5*cos(3*x**2)
 
    # - 4.5*cos(3*x**2)
    power(x,2,tmp)
    tmp *= 3
    cos(tmp,tmp)
    tmp *= 4.5
    z -= tmp
 

src/a/u/aureservoir-HEAD/python/examples/filtering.py   aureservoir(Download)
	Afilt = N.zeros(3)    # feedback path
 
	if( ftype=='LPF' ):
		Bfilt[0] = (1 - N.cos(w0)) / 2.
		Bfilt[1] = 1 - N.cos(w0)
		Bfilt[2] = (1 - N.cos(w0)) / 2.
		Afilt[0] = 1 + alpha
		Afilt[1] = -2*N.cos(w0)
		Afilt[2] = 1 - alpha
	elif( ftype=='HPF' ):
		Bfilt[0] = (1 + N.cos(w0))/2.
		Bfilt[1] = -(1 + N.cos(w0))
		Bfilt[2] = (1 + N.cos(w0))/2.
		Bfilt[1] = -(1 + N.cos(w0))
		Bfilt[2] = (1 + N.cos(w0))/2.
		Afilt[0] = 1 + alpha
		Afilt[1] = -2*N.cos(w0)
		Afilt[2] = 1 - alpha
	elif( ftype=='BPF' ):
		# constant 0dB peak gain
		Bfilt[0] = alpha
		Bfilt[1] = 0
		Bfilt[2] = -alpha
		Afilt[0] = 1 + alpha
		Afilt[1] = -2*N.cos(w0)
		Afilt[2] = 1 - alpha
	elif( ftype=='notch' ):
		Bfilt[0] = 1.
		Bfilt[1] = -2*N.cos(w0)
		Bfilt[2] = 1.
		Afilt[0] = 1 + alpha
		Afilt[1] = -2*N.cos(w0)
		Afilt[2] = 1 - alpha
	elif( ftype=='APF' ):
		Bfilt[0] = 1 - alpha
		Bfilt[1] = -2*N.cos(w0)
		Bfilt[2] = 1 + alpha
		Afilt[0] = 1 + alpha
		Afilt[1] = -2*N.cos(w0)
		Afilt[2] = 1 - alpha
	elif( ftype=='peakingEQ' ):
		Bfilt[0] = 1 + alpha*A
		Bfilt[1] = -2*N.cos(w0)
		Bfilt[2] = 1 - alpha*A
		Afilt[0] = 1 + alpha/A
		Afilt[1] = -2*N.cos(w0)
		Afilt[2] = 1 - alpha/A
	elif( ftype=='lowShelf' ):
		Bfilt[0] = A*((A+1)-(A-1)*N.cos(w0) + 2*N.sqrt(A)*alpha)
		Bfilt[1] = 2*A*( (A-1) - (A+1)*N.cos(w0) )
		Bfilt[2] = A*((A+1)-(A-1)*N.cos(w0)-2*N.sqrt(A)*alpha)
		Afilt[0] = (A+1)+(A-1)*N.cos(w0)+2*N.sqrt(A)*alpha
		Afilt[1] = -2*( (A-1) + (A+1)*N.cos(w0))
		Bfilt[2] = A*((A+1)-(A-1)*N.cos(w0)-2*N.sqrt(A)*alpha)
		Afilt[0] = (A+1)+(A-1)*N.cos(w0)+2*N.sqrt(A)*alpha
		Afilt[1] = -2*( (A-1) + (A+1)*N.cos(w0))
		Afilt[2] = (A+1) + (A-1)*N.cos(w0)-2*N.sqrt(A)*alpha
	elif( ftype=='highShelf' ):
		Bfilt[0] = A*((A+1)+(A-1)*N.cos(w0)+2*N.sqrt(A)*alpha)
		Bfilt[1] = -2*A*( (A-1) + (A+1)*N.cos(w0) )
		Bfilt[2] = A*( (A+1) + (A-1)*N.cos(w0)-2*N.sqrt(A)*alpha )
		Afilt[0] = (A+1) - (A-1)*N.cos(w0) + 2*N.sqrt(A)*alpha
		Afilt[1] = 2*( (A-1) - (A+1)*N.cos(w0) )
		Afilt[2] = (A+1) - (A-1)*N.cos(w0) - 2*N.sqrt(A)*alpha
	# calculate gain factor
	gain = abs( (-2*N.exp(4*1j*cf*N.pi*T)*T + \
	       2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \
	       (N.cos(2*cf*N.pi*T) - N.sqrt(3. - 2**(3./2.)) * \
	       N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \
	       2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \
	       (N.cos(2*cf*N.pi*T) + N.sqrt(3. - 2**(3./2.)) * \
	       N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \
	       2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) - \
	       N.sqrt(3. + 2**(3./2.)) * N.sin(2*cf*N.pi*T))) * \
	       (-2*N.exp(4*1j*cf*N.pi*T)*T + 2*N.exp(-(B*T) + \
	       2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) + \
	Afilt = N.zeros((len(cf),9))  # feedback path
	Bfilt = N.zeros((len(cf),5))  # forward path
	Bfilt[:,0] = T**4 / gain
	Bfilt[:,1] = -4*T**4*N.cos(2*cf*N.pi*T) / N.exp(B*T) / gain
	Bfilt[:,2] = 6*T**4*N.cos(4*cf*N.pi*T) / N.exp(2*B*T) / gain
	Bfilt[:,3] = -4*T**4*N.cos(6*cf*N.pi*T) / N.exp(3*B*T) / gain
	Bfilt[:,4] =  T**4*N.cos(8*cf*N.pi*T) / N.exp(4*B*T) / gain
	Afilt[:,0] = 1.
	Afilt[:,1] = -8*N.cos(2*cf*N.pi*T) / N.exp(B*T)
	Afilt[:,2] = 4*(4 + 3*N.cos(4*cf*N.pi*T)) / N.exp(2*B*T)
	Afilt[:,3] = -8*(6*N.cos(2*cf*N.pi*T) + N.cos(6*cf*N.pi*T)) / N.exp(3*B*T)
	Afilt[:,4] = 2*(18 + 16*N.cos(4*cf*N.pi*T)+N.cos(8*cf*N.pi*T)) / N.exp(4*B*T)
	Afilt[:,5] = -8*(6*N.cos(2*cf*N.pi*T) + N.cos(6*cf*N.pi*T)) / N.exp(5*B*T)
	Afilt[:,6] = 4*(4 + 3*N.cos(4*cf*N.pi*T)) / N.exp(6*B*T)
	Afilt[:,4] = 2*(18 + 16*N.cos(4*cf*N.pi*T)+N.cos(8*cf*N.pi*T)) / N.exp(4*B*T)
	Afilt[:,5] = -8*(6*N.cos(2*cf*N.pi*T) + N.cos(6*cf*N.pi*T)) / N.exp(5*B*T)
	Afilt[:,6] = 4*(4 + 3*N.cos(4*cf*N.pi*T)) / N.exp(6*B*T)
	Afilt[:,7] = -8*N.cos(2*cf*N.pi*T) / N.exp(7*B*T)
	Afilt[:,8] = N.exp(-8*B*T)
 
	return Bfilt,Afilt
	# calculate gain factor
	gain = abs( (-2*N.exp(4*1j*cf*N.pi*T)*T + \
	       2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \
	       (N.cos(2*cf*N.pi*T) - N.sqrt(3. - 2**(3./2.)) * \
	       N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \
	       2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \
	       (N.cos(2*cf*N.pi*T) + N.sqrt(3. - 2**(3./2.)) * \
	       N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \
	       2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) - \
	       N.sqrt(3. + 2**(3./2.)) * N.sin(2*cf*N.pi*T))) * \
	       (-2*N.exp(4*1j*cf*N.pi*T)*T + 2*N.exp(-(B*T) + \
	       2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) + \
	# init all 4 biquads
	for n in range(4):
		Afilt[:,n,0] = 1.
		Afilt[:,n,1] = -2 * N.cos(2*cf*N.pi*T) / N.exp(B*T)
		Afilt[:,n,2] = N.exp(-2*B*T)
		Bfilt[:,n,0] = T
		Bfilt[:,n,2] = 0.
 
	# init the rest
	tmp = 2*T*N.cos(2*cf*N.pi*T) / N.exp(B*T)

src/p/y/pyfusion-HEAD/examples/Boyds/wid_specgram.py   pyfusion(Download)
"""
from matplotlib.widgets import RadioButtons, Button
import pylab as pl
from numpy import sin, pi, ones, hanning, hamming, bartlett, kaiser, arange, blackman, cos, sqrt, log10, fft
 
import pyfusion
 
def local_wider(vec):
    """ Flat top in middle, cos at edges - meant to be narrower in f
    but not as good in the wings
    """
    N=len(vec)
    k=arange(N)
    w = sqrt(sqrt(1 - cos(2*pi*k/(N-1))))
def local_flat_top_freq(vec):
    N=len(vec)
    k=arange(N)
    w = (1 - 1.93*cos(2*pi*k/(N-1)) + 1.29*cos(4*pi*k/(N-1)) 
         -0.388*cos(6*pi*k/(N-1)) +0.032*cos(8*pi*k/(N-1)))
    return(w)
 

src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/quadmesh_demo.py   matplotlib(Download)
x = np.linspace(-1.5,1.5,n)
y = np.linspace(-1.5,1.5,n*2)
X,Y = np.meshgrid(x,y);
Qx = np.cos(Y) - np.cos(X)
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.sqrt(X**2 + Y**2)/5;

src/m/a/matplotlib-HEAD/examples/pylab_examples/quadmesh_demo.py   matplotlib(Download)
x = np.linspace(-1.5,1.5,n)
y = np.linspace(-1.5,1.5,n*2)
X,Y = np.meshgrid(x,y);
Qx = np.cos(Y) - np.cos(X)
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.sqrt(X**2 + Y**2)/5;

src/a/l/algopy-HEAD/documentation/AD_tutorial_TU_Berlin/example7_simple_computation_of_the_hessian.py   algopy(Download)
at x = (3,7)
"""
 
import numpy; from numpy import sin,cos, array, zeros
from taylorpoly import UTPS
def f_fcn(x):
    return sin(x[0] + cos(x[1])*x[0])
def H_fcn(x):
    H11 = -(1+cos(x[1]))**2*sin(x[0]+cos(x[1])*x[0])
    H21 = -sin(x[1]) * cos(x[0] + cos(x[1])*x[0]) \
          +sin(x[1]) *x[0]*(1+ cos(x[1]))*sin(x[0]+cos(x[1])*x[0])
    H22 = -cos(x[1])*x[0]*cos(x[0]+cos(x[1])*x[0])\
          -(sin(x[1])*x[0])**2*sin(x[0]+cos(x[1])*x[0])
    return array([[H11, H21],[H21,H22]])

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:
        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)
            with self.env:
                # check the IK of the destination
    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)

src/m/a/Matplotlib--JJ-s-dev-HEAD/examples/pylab_examples/quadmesh_demo.py   Matplotlib--JJ-s-dev(Download)
x = np.linspace(-1.5,1.5,n)
y = np.linspace(-1.5,1.5,n*2)
X,Y = np.meshgrid(x,y);
Qx = np.cos(Y) - np.cos(X)
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.sqrt(X**2 + Y**2)/5;

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:
        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)
            with self.env:
                # check the IK of the destination
    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)

src/m/a/matplotlib-HEAD/matplotlib/examples/mplot3d/surface3d_demo2.py   matplotlib(Download)
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
 
x = 10 * np.outer(np.cos(u), np.sin(v))
y = 10 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
ax.plot_surface(x, y, z,  rstride=4, cstride=4, color='b')

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