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 shapesrc/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/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/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/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/a/l/algopy-HEAD/documentation/sphinx/examples/first_order_forward.py algopy(Download)
import numpy; from numpy import log, exp, sin, cos, abs
import algopy; from algopy import UTPM, dot, inv, zeros
def f(x):
A = zeros((2,2),dtype=x)
A[0,0] = numpy.log(x[0]*x[1])
A[0,1] = numpy.log(x[1]) + exp(x[0])
A[1,0] = sin(x[0])**2 + abs(cos(x[0]))**3.1
A[1,1] = x[0]**cos(x[1])
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/scatter_custom_symbol.py matplotlib(Download)
from matplotlib.pyplot import figure, show from numpy import arange, pi, cos, sin, pi from numpy.random import rand # unit area ellipse rx, ry = 3., 1. area = rx * ry * pi theta = arange(0, 2*pi+0.01, 0.1) verts = zip(rx/area*cos(theta), ry/area*sin(theta))
src/m/a/matplotlib-HEAD/examples/pylab_examples/scatter_custom_symbol.py matplotlib(Download)
from matplotlib.pyplot import figure, show from numpy import arange, pi, cos, sin, pi from numpy.random import rand # unit area ellipse rx, ry = 3., 1. area = rx * ry * pi theta = arange(0, 2*pi+0.01, 0.1) verts = zip(rx/area*cos(theta), ry/area*sin(theta))
src/m/a/Matplotlib--JJ-s-dev-HEAD/examples/pylab_examples/scatter_custom_symbol.py Matplotlib--JJ-s-dev(Download)
from matplotlib.pyplot import figure, show from numpy import arange, pi, cos, sin, pi from numpy.random import rand # unit area ellipse rx, ry = 3., 1. area = rx * ry * pi theta = arange(0, 2*pi+0.01, 0.1) verts = zip(rx/area*cos(theta), ry/area*sin(theta))
src/p/y/pydy-HEAD/examples/reaction_wheel/rxnw_eoms.py pydy(Download)
# Tue Aug 25 17:42:58 2009
from numpy import sin, cos, tan, vectorize
def f(x, t, parameter_list):
# Unpacking the parameters
m1, m2, I1, I2, J1, J2, l, M = parameter_list
# Unpacking the states (q's and u's)
q1, q2, q3, q4, q5, q6, q7, q8, u1, u2, u3, u4, u5, u6, u7, u8 = x
c3 = cos(q3)
c2 = cos(q2)
s1 = sin(q1)
s2 = sin(q2)
c1 = cos(q1)
def qdot2u(q, qd, parameter_list):
# Unpacking the parameters
m1, m2, I1, I2, J1, J2, l, M = parameter_list
# Unpacking the q's and qdots
q1, q2, q3, q4, q5, q6, q7, q8 = q
q1p, q2p, q3p, q4p, q5p, q6p, q7p, q8p = qd
c3 = cos(q3)
c2 = cos(q2)
s1 = sin(q1)
s2 = sin(q2)
c1 = cos(q1)
def animate(q, parameter_list):
# Unpacking the parameters
m1, m2, I1, I2, J1, J2, l, M = parameter_list
# Unpacking the coordinates
q1, q2, q3, q4, q5, q6, q7, q8 = q
# Trigonometric functions needed
c3 = cos(q3)
s5 = sin(q5)
c2 = cos(q2)
c5 = cos(q5)
s1 = sin(q1)
s2 = sin(q2)
c1 = cos(q1)
c4 = cos(q4)
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next