本文整理汇总了Python中numpy.sin方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.sin方法的具体用法?Python numpy.sin怎么用?Python numpy.sin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.sin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unit_vec
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def unit_vec(doa):
"""
This function takes a 2D (phi) or 3D (phi,theta) polar coordinates
and returns a unit vector in cartesian coordinates.
:param doa: (ndarray) An (D-1)-by-N array where D is the dimension and
N the number of vectors.
:return: (ndarray) A D-by-N array of unit vectors (each column is a vector)
"""
if doa.ndim != 1 and doa.ndim != 2:
raise ValueError("DoA array should be 1D or 2D.")
doa = np.array(doa)
if doa.ndim == 0 or doa.ndim == 1:
return np.array([np.cos(doa), np.sin(doa)])
elif doa.ndim == 2 and doa.shape[0] == 1:
return np.array([np.cos(doa[0]), np.sin(doa[0])])
elif doa.ndim == 2 and doa.shape[0] == 2:
s = np.sin(doa[1])
return np.array([s * np.cos(doa[0]), s * np.sin(doa[0]), np.cos(doa[1])])
示例2: load_RSM
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def load_RSM(filename):
om, tt, psd = xu.io.getxrdml_map(filename)
om = np.deg2rad(om)
tt = np.deg2rad(tt)
wavelength = 1.54056
q_y = (1 / wavelength) * (np.cos(tt) - np.cos(2 * om - tt))
q_x = (1 / wavelength) * (np.sin(tt) - np.sin(2 * om - tt))
xi = np.linspace(np.min(q_x), np.max(q_x), 100)
yi = np.linspace(np.min(q_y), np.max(q_y), 100)
psd[psd < 1] = 1
data_grid = griddata(
(q_x, q_y), psd, (xi[None, :], yi[:, None]), fill_value=1, method="cubic"
)
nx, ny = data_grid.shape
range_values = [np.min(q_x), np.max(q_x), np.min(q_y), np.max(q_y)]
output_data = (
Panel(np.log(data_grid).reshape(nx, ny, 1), minor_axis=["RSM"])
.transpose(2, 0, 1)
.to_frame()
)
return range_values, output_data
示例3: rotation_matrix_3D
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def rotation_matrix_3D(u, th):
"""
rotation_matrix_3D(u, t) yields a 3D numpy matrix that rotates any vector about the axis u
t radians counter-clockwise.
"""
# normalize the axis:
u = normalize(u)
# We use the Euler-Rodrigues formula;
# see https://en.wikipedia.org/wiki/Euler-Rodrigues_formula
a = math.cos(0.5 * th)
s = math.sin(0.5 * th)
(b, c, d) = -s * u
(a2, b2, c2, d2) = (a*a, b*b, c*c, d*d)
(bc, ad, ac, ab, bd, cd) = (b*c, a*d, a*c, a*b, b*d, c*d)
return np.array([[a2 + b2 - c2 - d2, 2*(bc + ad), 2*(bd - ac)],
[2*(bc - ad), a2 + c2 - b2 - d2, 2*(cd + ab)],
[2*(bd + ac), 2*(cd - ab), a2 + d2 - b2 - c2]])
示例4: get_rotation_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def get_rotation_matrix(rotationVector, angle):
"""
Calculate the rotation (3X3) matrix about an axis (rotationVector)
by a rotation angle.
:Parameters:
#. rotationVector (list, tuple, numpy.ndarray): Rotation axis
coordinates.
#. angle (float): Rotation angle in rad.
:Returns:
#. rotationMatrix (numpy.ndarray): Computed (3X3) rotation matrix
"""
angle = float(angle)
axis = rotationVector/np.sqrt(np.dot(rotationVector , rotationVector))
a = np.cos(angle/2)
b,c,d = -axis*np.sin(angle/2.)
return np.array( [ [a*a+b*b-c*c-d*d, 2*(b*c-a*d), 2*(b*d+a*c)],
[2*(b*c+a*d), a*a+c*c-b*b-d*d, 2*(c*d-a*b)],
[2*(b*d-a*c), 2*(c*d+a*b), a*a+d*d-b*b-c*c] ] , dtype = FLOAT_TYPE)
示例5: get_loc_axis
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def get_loc_axis(self, node, delta_theta, perturb=None):
"""Based on the node orientation returns X, and Y axis. Used to sample the
map in egocentric coordinate frame.
"""
if type(node) == tuple:
node = np.array([node])
if perturb is None:
perturb = np.zeros((node.shape[0], 4))
xyt = self.to_actual_xyt_vec(node)
x = xyt[:,[0]] + perturb[:,[0]]
y = xyt[:,[1]] + perturb[:,[1]]
t = xyt[:,[2]] + perturb[:,[2]]
theta = t*delta_theta
loc = np.concatenate((x,y), axis=1)
x_axis = np.concatenate((np.cos(theta), np.sin(theta)), axis=1)
y_axis = np.concatenate((np.cos(theta+np.pi/2.), np.sin(theta+np.pi/2.)),
axis=1)
# Flip the sampled map where need be.
y_axis[np.where(perturb[:,3] > 0)[0], :] *= -1.
return loc, x_axis, y_axis, theta
示例6: sample
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def sample(self):
"""Samples new points around some existing point.
Removes the sampling base point and also stores the new jksampled points if
they are far enough from all existing points.
"""
active_point = self._active_list.pop()
for _ in xrange(self._max_sample_size):
# Generate random points near the current active_point between the radius
random_radius = np.random.uniform(self._min_radius, 2 * self._min_radius)
random_angle = np.random.uniform(0, 2 * math.pi)
# The sampled 2D points near the active point
sample = random_radius * np.array(
[np.cos(random_angle), np.sin(random_angle)]) + active_point
if not self._is_in_grid(sample):
continue
if self._is_close_to_existing_points(sample):
continue
self._active_list.append(sample)
self._grid[self._point_to_index_1d(sample)] = sample
示例7: alive_bonus
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def alive_bonus(self, z, pitch):
if self.frame%30==0 and self.frame>100 and self.on_ground_frame_counter==0:
target_xyz = np.array(self.body_xyz)
robot_speed = np.array(self.robot_body.speed())
angle = self.np_random.uniform(low=-3.14, high=3.14)
from_dist = 4.0
attack_speed = self.np_random.uniform(low=20.0, high=30.0) # speed 20..30 (* mass in cube.urdf = impulse)
time_to_travel = from_dist / attack_speed
target_xyz += robot_speed*time_to_travel # predict future position at the moment the cube hits the robot
position = [target_xyz[0] + from_dist*np.cos(angle),
target_xyz[1] + from_dist*np.sin(angle),
target_xyz[2] + 1.0]
attack_speed_vector = target_xyz - np.array(position)
attack_speed_vector *= attack_speed / np.linalg.norm(attack_speed_vector)
attack_speed_vector += self.np_random.uniform(low=-1.0, high=+1.0, size=(3,))
self.aggressive_cube.reset_position(position)
self.aggressive_cube.reset_velocity(linearVelocity=attack_speed_vector)
if z < 0.8:
self.on_ground_frame_counter += 1
elif self.on_ground_frame_counter > 0:
self.on_ground_frame_counter -= 1
# End episode if the robot can't get up in 170 frames, to save computation and decorrelate observations.
self.frame += 1
return self.potential_leak() if self.on_ground_frame_counter<170 else -1
示例8: calc_state
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def calc_state(self):
theta, self.theta_dot = self.central_joint.current_relative_position()
self.gamma, self.gamma_dot = self.elbow_joint.current_relative_position()
target_x, _ = self.jdict["target_x"].current_position()
target_y, _ = self.jdict["target_y"].current_position()
self.to_target_vec = np.array(self.fingertip.pose().xyz()) - np.array(self.target.pose().xyz())
return np.array([
target_x,
target_y,
self.to_target_vec[0],
self.to_target_vec[1],
np.cos(theta),
np.sin(theta),
self.theta_dot,
self.gamma,
self.gamma_dot,
])
示例9: calc_state
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def calc_state(self):
self.theta, theta_dot = self.j1.current_position()
x, vx = self.slider.current_position()
assert( np.isfinite(x) )
if not np.isfinite(x):
print("x is inf")
x = 0
if not np.isfinite(vx):
print("vx is inf")
vx = 0
if not np.isfinite(self.theta):
print("theta is inf")
self.theta = 0
if not np.isfinite(theta_dot):
print("theta_dot is inf")
theta_dot = 0
return np.array([
x, vx,
np.cos(self.theta), np.sin(self.theta), theta_dot
])
示例10: random_quat
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def random_quat(rand=None):
"""Return uniform random unit quaternion.
rand: array like or None
Three independent random variables that are uniformly distributed
between 0 and 1.
>>> q = random_quat()
>>> np.allclose(1.0, vector_norm(q))
True
>>> q = random_quat(np.random.random(3))
>>> q.shape
(4,)
"""
if rand is None:
rand = np.random.rand(3)
else:
assert len(rand) == 3
r1 = np.sqrt(1.0 - rand[0])
r2 = np.sqrt(rand[0])
pi2 = math.pi * 2.0
t1 = pi2 * rand[1]
t2 = pi2 * rand[2]
return np.array(
(np.sin(t1) * r1, np.cos(t1) * r1, np.sin(t2) * r2, np.cos(t2) * r2),
dtype=np.float32,
)
示例11: subspace_disagreement_measure
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def subspace_disagreement_measure(self, Ps, Pt, Pst):
"""
Get the best value for the number of subspaces
For more details, read section 3.4 of the paper.
**Parameters**
Ps: Source subspace
Pt: Target subspace
Pst: Source + Target subspace
"""
def compute_angles(A, B):
_, S, _ = np.linalg.svd(np.dot(A.T, B))
S[np.where(np.isclose(S, 1, atol=self.eps) == True)[0]] = 1
return np.arccos(S)
max_d = min(Ps.shape[1], Pt.shape[1], Pst.shape[1])
alpha_d = compute_angles(Ps, Pst)
beta_d = compute_angles(Pt, Pst)
d = 0.5 * (np.sin(alpha_d) + np.sin(beta_d))
return np.argmax(d)
示例12: cosine
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def cosine(M):
"""Gernerate a halfcosine window of given length
Uses :code:`scipy.signal.cosine` by default. However since this window
function has only recently been merged into mainline SciPy, a fallback
calculation is in place.
Parameters
----------
M : int
Length of the window.
Returns
-------
data : array_like
The window function
"""
try:
import scipy.signal
return scipy.signal.cosine(M)
except AttributeError:
return numpy.sin(numpy.pi / M * (numpy.arange(0, M) + .5))
示例13: test_analytical
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def test_analytical():
"""
Run the test model though a year with analytical solution values to
ensure reservoir just contains sufficient volume.
"""
S = 100.0 # supply amplitude
D = S # demand
w = 2*np.pi/365 # frequency (annual)
V0 = S/w # initial reservoir level
model = make_simple_model(S, D, w, V0)
T = np.arange(1, 365)
V_anal = S*(np.sin(w*T)/w+T) - D*T + V0
V_model = np.empty(T.shape)
for i, t in enumerate(T):
model.step()
V_model[i] = model.nodes['reservoir'].volume[0]
# Relative error from initial volume
error = np.abs(V_model - V_anal) / V0
assert np.all(error < 1e-4)
示例14: mindmag
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def mindmag(self, s):
"""Calculates the minimum value of dMag for projected separation
Args:
s (float):
Projected separations (AU)
Returns:
mindmag (float):
Minimum planet delta magnitude
"""
if s == 0.0:
mindmag = self.cdmin1
elif s < self.rmin*np.sin(self.bstar):
mindmag = self.cdmin1-2.5*np.log10(self.Phi(np.arcsin(s/self.rmin)))
elif s < self.rmax*np.sin(self.bstar):
mindmag = self.cdmin2+5.0*np.log10(s)
elif s <= self.rmax:
mindmag = self.cdmin3-2.5*np.log10(self.Phi(np.arcsin(s/self.rmax)))
else:
mindmag = np.inf
return mindmag
示例15: Jac
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sin [as 别名]
def Jac(self, b):
"""Calculates determinant of the Jacobian transformation matrix to get
the joint probability density of dMag and s
Args:
b (ndarray):
Phase angles
Returns:
f (ndarray):
Determinant of Jacobian transformation matrix
"""
f = -2.5/(self.Phi(b)*np.log(10.0))*self.dPhi(b)*np.sin(b) - 5./np.log(10.0)*np.cos(b)
return f