本文整理汇总了Python中numpy.dot方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.dot方法的具体用法?Python numpy.dot怎么用?Python numpy.dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: similarity_label
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def similarity_label(self, words, normalization=True):
"""
you can calculate more than one word at the same time.
"""
if self.model==None:
raise Exception('no model.')
if isinstance(words, string_types):
words=[words]
vectors=np.transpose(self.model.wv.__getitem__(words))
if normalization:
unit_vector=unitvec(vectors,ax=0) # 这样写比原来那样速度提升一倍
#unit_vector=np.zeros((len(vectors),len(words)))
#for i in range(len(words)):
# unit_vector[:,i]=matutils.unitvec(vectors[:,i])
dists=np.dot(self.Label_vec_u, unit_vector)
else:
dists=np.dot(self.Label_vec, vectors)
return dists
示例2: classical_mds
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def classical_mds(self, D):
'''
Classical multidimensional scaling
Parameters
----------
D : square 2D ndarray
Euclidean Distance Matrix (matrix containing squared distances between points
'''
# Apply MDS algorithm for denoising
n = D.shape[0]
J = np.eye(n) - np.ones((n,n))/float(n)
G = -0.5*np.dot(J, np.dot(D, J))
s, U = np.linalg.eig(G)
# we need to sort the eigenvalues in decreasing order
s = np.real(s)
o = np.argsort(s)
s = s[o[::-1]]
U = U[:,o[::-1]]
S = np.diag(s)[0:self.dim,:]
self.X = np.dot(np.sqrt(S),U.T)
示例3: flatten
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def flatten(self, ind):
'''
Transform the set of points so that the subset of markers given as argument is
as close as flat (wrt z-axis) as possible.
Parameters
----------
ind : list of bools
Lists of marker indices that should be all in the same subspace
'''
# Transform references to indices if needed
ind = [self.key2ind(s) for s in ind]
# center point cloud around the group of indices
centroid = self.X[:,ind].mean(axis=1, keepdims=True)
X_centered = self.X - centroid
# The rotation is given by left matrix of SVD
U,S,V = la.svd(X_centered[:,ind], full_matrices=False)
self.X = np.dot(U.T, X_centered) + centroid
示例4: gen_visibility
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def gen_visibility(alphak, phi_k, pos_mic_x, pos_mic_y):
"""
generate visibility from the Dirac parameter and microphone array layout
:param alphak: Diracs' amplitudes
:param phi_k: azimuths
:param pos_mic_x: a vector that contains microphones' x coordinates
:param pos_mic_y: a vector that contains microphones' y coordinates
:return:
"""
xk, yk = polar2cart(1, phi_k)
num_mic = pos_mic_x.size
visi = np.zeros((num_mic, num_mic), dtype=complex)
for q in xrange(num_mic):
p_x_outer = pos_mic_x[q]
p_y_outer = pos_mic_y[q]
for qp in xrange(num_mic):
p_x_qqp = p_x_outer - pos_mic_x[qp] # a scalar
p_y_qqp = p_y_outer - pos_mic_y[qp] # a scalar
visi[qp, q] = np.dot(np.exp(-1j * (xk * p_x_qqp + yk * p_y_qqp)), alphak)
return visi
示例5: compute_mode
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def compute_mode(self):
"""
Pre-compute mode vectors from candidate locations (in spherical
coordinates).
"""
if self.num_loc is None:
raise ValueError('Lookup table appears to be empty. \
Run build_lookup().')
self.mode_vec = np.zeros((self.max_bin,self.M,self.num_loc),
dtype='complex64')
if (self.nfft % 2 == 1):
raise ValueError('Signal length must be even.')
f = 1.0 / self.nfft * np.linspace(0, self.nfft / 2, self.max_bin) \
* 1j * 2 * np.pi
for i in range(self.num_loc):
p_s = self.loc[:, i]
for m in range(self.M):
p_m = self.L[:, m]
if (self.mode == 'near'):
dist = np.linalg.norm(p_m - p_s, axis=1)
if (self.mode == 'far'):
dist = np.dot(p_s, p_m)
# tau = np.round(self.fs*dist/self.c) # discrete - jagged
tau = self.fs * dist / self.c # "continuous" - smoother
self.mode_vec[:, m, i] = np.exp(f * tau)
示例6: cov_mtx_est
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def cov_mtx_est(y_mic):
"""
estimate covariance matrix
:param y_mic: received signal (complex based band representation) at microphones
:return:
"""
# Q: total number of microphones
# num_snapshot: number of snapshots used to estimate the covariance matrix
Q, num_snapshot = y_mic.shape
cov_mtx = np.zeros((Q, Q), dtype=complex, order='F')
for q in range(Q):
y_mic_outer = y_mic[q, :]
for qp in range(Q):
y_mic_inner = y_mic[qp, :]
cov_mtx[qp, q] = np.dot(y_mic_outer, y_mic_inner.T.conj())
return cov_mtx / num_snapshot
示例7: mtx_updated_G
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def mtx_updated_G(phi_recon, M, mtx_amp2visi_ri, mtx_fri2visi_ri):
"""
Update the linear transformation matrix that links the FRI sequence to the
visibilities by using the reconstructed Dirac locations.
:param phi_recon: the reconstructed Dirac locations (azimuths)
:param M: the Fourier series expansion is between -M to M
:param p_mic_x: a vector that contains microphones' x-coordinates
:param p_mic_y: a vector that contains microphones' y-coordinates
:param mtx_freq2visi: the linear mapping from Fourier series to visibilities
:return:
"""
L = 2 * M + 1
ms_half = np.reshape(np.arange(-M, 1, step=1), (-1, 1), order='F')
phi_recon = np.reshape(phi_recon, (1, -1), order='F')
mtx_amp2freq = np.exp(-1j * ms_half * phi_recon) # size: (M + 1) x K
mtx_amp2freq_ri = np.vstack((mtx_amp2freq.real, mtx_amp2freq.imag[:-1, :])) # size: (2M + 1) x K
mtx_fri2amp_ri = linalg.lstsq(mtx_amp2freq_ri, np.eye(L))[0]
# projection mtx_freq2visi to the null space of mtx_fri2amp
mtx_null_proj = np.eye(L) - np.dot(mtx_fri2amp_ri.T,
linalg.lstsq(mtx_fri2amp_ri.T, np.eye(L))[0])
G_updated = np.dot(mtx_amp2visi_ri, mtx_fri2amp_ri) + \
np.dot(mtx_fri2visi_ri, mtx_null_proj)
return G_updated
示例8: prep_graph_display
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def prep_graph_display(states, options={}):
clean_states = [x.tolist() for x in states]
nstr, nid, nstate, estr = states
flat_nid = nid.reshape([-1,nid.shape[-1]])
flat_estr = estr.reshape([-1,estr.shape[-1]])
flat_estr = flat_estr / (np.linalg.norm(flat_estr, axis=1, keepdims=True) + 1e-8)
num_unique_colors = nid.shape[-1] + estr.shape[-1]
id_denom = max(nid.shape[-1] - 1, 1)
id_project_mat = np.array([list(cm_rainbow(i/id_denom)[:3]) for i in range(0,nid.shape[-1])])
estr_denom = estr.shape[-1]
estr_project_mat = np.array([list(cm_rainbow((i+0.37)/estr_denom)[:3]) for i in range(estr.shape[-1])])
node_colors = np.dot(flat_nid, id_project_mat)
edge_colors = np.dot(flat_estr, estr_project_mat)
colormap = {
"node_id": node_colors.reshape(nid.shape[:-1] + (3,)).tolist(),
"edge_type": edge_colors.reshape(estr.shape[:-1] + (3,)).tolist(),
}
return json.dumps({
"states":clean_states,
"colormap":colormap,
"options":options
})
示例9: Riz_mode
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def Riz_mode(model:Model,n,F):
"""
Solve the Riz mode of the MDOF system\n
n: number of modes to extract\n
F: spacial load pattern
"""
# alpha=np.array(mode).T
# #Grum-Schmidt procedure
# beta=[]
# for i in range(len(mode)):
# beta_i=alpha[i]
# for j in range(i):
# beta_i-=np.dot(alpha[i],beta[j])/np.dot(alpha[j],alpha[j])*beta[j]
# beta.append(beta_i)
# mode_=np.array(beta).T
pass
示例10: spectrum_analysis
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def spectrum_analysis(model,n,spec):
"""
sepctrum analysis
params:
n: number of modes to use\n
spec: a list of tuples (period,acceleration response)
"""
freq,mode=eigen_mode(model,n)
M_=np.dot(mode.T,model.M)
M_=np.dot(M_,mode)
K_=np.dot(mode.T,model.K)
K_=np.dot(K_,mode)
C_=np.dot(mode.T,model.C)
C_=np.dot(C_,mode)
d_=[]
for (m_,k_,c_) in zip(M_.diag(),K_.diag(),C_.diag()):
sdof=SDOFSystem(m_,k_)
T=sdof.omega_d()
d_.append(np.interp(T,spec[0],spec[1]*m_))
d=np.dot(d_,mode)
#CQC
return d
示例11: resolve_modal_displacement
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def resolve_modal_displacement(self,node_id,k):
"""
resolve modal node displacement.
params:
node_id: int.
k: order of vibration mode.
return:
6-array of local nodal displacement.
"""
if not self.is_solved:
raise Exception('The model has to be solved first.')
if node_id in self.__nodes.keys():
node=self.__nodes[node_id]
T=node.transform_matrix
return T.dot(self.mode_[node_id*6:node_id*6+6,k-1]).reshape(6)
else:
raise Exception("The node doesn't exists.")
示例12: _BtDB
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def _BtDB(self,s,r):
"""
dot product of B^T, D, B
params:
s,r:natural position of evalue point.2-array.
returns:
3x3 matrix.
"""
print(self._B(s,r).transpose(2,0,1).shape)
print(
np.matmul(
np.dot(self._B(s,r).T,self._D),
self._B(s,r).transpose(2,0,1)).shape
)
print(self._D.shape)
return np.matmul(np.dot(self._B(s,r).T,self._D),self._B(s,r).transpose(2,0,1)).transpose(1,2,0)
示例13: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def __init__(self,origin, pt1, pt2, name=None):
"""
origin: 3x1 vector
pt1: 3x1 vector
pt2: 3x1 vector
"""
self.__origin=origin
vec1 = np.array([pt1[0] - origin[0] , pt1[1] - origin[1] , pt1[2] - origin[2]])
vec2 = np.array([pt2[0] - origin[0] , pt2[1] - origin[1] , pt2[2] - origin[2]])
cos = np.dot(vec1, vec2)/np.linalg.norm(vec1)/np.linalg.norm(vec2)
if cos == 1 or cos == -1:
raise Exception("Three points should not in a line!!")
self.__x = vec1/np.linalg.norm(vec1)
z = np.cross(vec1, vec2)
self.__z = z/np.linalg.norm(z)
self.__y = np.cross(self.z, self.x)
self.__name=uuid.uuid1() if name==None else name
示例14: set_by_3pts
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def set_by_3pts(self,origin, pt1, pt2):
"""
origin: tuple 3
pt1: tuple 3
pt2: tuple 3
"""
self.origin=origin
vec1 = np.array([pt1[0] - origin[0] , pt1[1] - origin[1] , pt1[2] - origin[2]])
vec2 = np.array([pt2[0] - origin[0] , pt2[1] - origin[1] , pt2[2] - origin[2]])
cos = np.dot(vec1, vec2)/np.linalg.norm(vec1)/np.linalg.norm(vec2)
if cos == 1 or cos == -1:
raise Exception("Three points should not in a line!!")
self.x = vec1/np.linalg.norm(vec1)
z = np.cross(vec1, vec2)
self.z = z/np.linalg.norm(z)
self.y = np.cross(self.z, self.x)
示例15: predict
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import dot [as 别名]
def predict(self):
"""Predict state vector u and variance of uncertainty P (covariance).
where,
u: previous state vector
P: previous covariance matrix
F: state transition matrix
Q: process noise matrix
Equations:
u'_{k|k-1} = Fu'_{k-1|k-1}
P_{k|k-1} = FP_{k-1|k-1} F.T + Q
where,
F.T is F transpose
Args:
None
Return:
vector of predicted state estimate
"""
# Predicted state estimate
self.u = np.round(np.dot(self.F, self.u))
# Predicted estimate covariance
self.P = np.dot(self.F, np.dot(self.P, self.F.T)) + self.Q
self.lastResult = self.u # same last predicted result
return self.u