本文整理汇总了Python中scipy.inner函数的典型用法代码示例。如果您正苦于以下问题:Python inner函数的具体用法?Python inner怎么用?Python inner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inner函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_direction
def find_direction(self, grad_diffs, steps, grad, hessian_diag, idxs):
grad = grad.copy() # We will change this.
n_current_factors = len(idxs)
# TODO: find a good name for this variable.
rho = scipy.empty(n_current_factors)
# TODO: vectorize this function
for i in idxs:
rho[i] = 1 / scipy.inner(grad_diffs[i], steps[i])
# TODO: find a good name for this variable as well.
alpha = scipy.empty(n_current_factors)
for i in idxs[::-1]:
alpha[i] = rho[i] * scipy.inner(steps[i], grad)
grad -= alpha[i] * grad_diffs[i]
z = hessian_diag * grad
# TODO: find a good name for this variable (surprise!)
beta = scipy.empty(n_current_factors)
for i in idxs:
beta[i] = rho[i] * scipy.inner(grad_diffs[i], z)
z += steps[i] * (alpha[i] - beta[i])
return z, {}
示例2: corelationImage1Image2
def corelationImage1Image2(imageArray1, imageArray2):
image1 = scipy.inner(numpy.asarray(imageArray1), [299, 587, 114]) / 1000.0
image2 = scipy.inner(numpy.asarray(imageArray2), [299, 587, 114]) / 1000.0
image1 = (image1 - image1.mean())/ image1.std()
image2 = (image2 - image2.mean())/ image2.std()
corelationimage1Withimage2 = c2d(image1, image2, mode = 'same')
return corelationimage1Withimage2.max()
示例3: convert_to_grayscale
def convert_to_grayscale(img):
shape = img.shape(img)
if len(shape) == 1:
return img
elif len(shape) == 3:
return sp.inner(img, [299, 587, 114]) / 1000
elif len(shape) == 4:
return sp.inner(img, [299, 587, 114, 0] / 1000)
elif len(shape) == 2:
return sp.inner(img, [1, 0])
else:
raise ValueError("The image has a non-standard bit-depth which is not supported.")
示例4: get
def get(i):
# get JPG image as Scipy array, RGB (3 layer)
data = imread('/Users/kalaivanikubendran/Documents/Sideprojects/kalai-kaggle-code/train_sm/set175_%s.jpeg' % i)
# convert to grey-scale using W3C luminance calc
data = sp.inner(data, [299, 587, 114]) / 1000.0
# normalize per http://en.wikipedia.org/wiki/Cross-correlation
return (data - data.mean()) / data.std()
示例5: grad_f1
def grad_f1(self, a):
"Define the gradient for each convex inequality."
# Initialize the output vector
out = sp.zeros((self.M, self.Na))
# Preliminary calculation
_xx = sp.einsum('mi,mj->mij', self.xarray, self.xarray)
# Compute the four terms
_Da = sp.tensordot(self.D, a, axes=[(0,), (0,)])
_DDa = sp.tensordot(self.D, _Da, axes=[(1,), (0,)])
xxDDa = sp.tensordot(_xx.reshape(self.M, self.ndim**2),
_DDa.reshape(self.Na, self.ndim**2),
axes=[(-1,), (-1,)])
_BDa = sp.dot(self.B, _Da)
xBDa = sp.inner(self.xarray, _BDa)
_Ba = sp.dot(a, self.B)
_DBa = sp.dot(_Ba, self.D)
xDBa = sp.tensordot(self.xarray,
_DBa, axes=[(-1,), (-1,)])
BBa = sp.dot(self.B, _Ba)
# compute the gradient by summing the four terms
out[:, :] = 2.0 * (xxDDa + xBDa + xDBa + BBa)
return out
示例6: norm
def norm(x):
"""2-norm of x
"""
y = ravel(x)
p = sqrt(inner(y, y))
return p
示例7: stateActionValue
def stateActionValue(self, feature):
r = self.tao(self.r) * self.r
if self.enableOnlyEssentialFeatureInCritic:
feature = self.module.decodeFeature(feature,
self.essentialFeature)
assert len(r) == self.criticdim, 'Wrong dimension of r'
return scipy.inner(r, feature)
示例8: get
def get(i):
# get JPG image as Scipy array, RGB (3 layer)
data = imread(i)
# convert to grey-scale using W3C luminance calc
data = sp.inner(data, [299, 587, 114]) / 1000.0
# normalize per http://en.wikipedia.org/wiki/Cross-correlation
return (data - data.mean()) / data.std()
示例9: prepare_image_for_correlation
def prepare_image_for_correlation(im):
letterArray = fromimage(im.convert('RGB'))
# Black and white
letterArray = scipy.inner(letterArray, [299, 587, 114]) / 1000.0
# Normalize
letterArray = (letterArray - letterArray.mean()) / letterArray.std()
return letterArray
示例10: normalize
def normalize(x):
n = scipy.sqrt(scipy.inner(x,x))
#n = sl.norm(x, scipy.inf)
if n > 0:
return x/n
else:
return x
示例11: get_resized_data
def get_resized_data(origdata, size):
'''Resize image data'''
tmp = imresize(origdata, (size, size), interp="bilinear", mode=None)
# convert to grey-scale using W3C luminance calc
lum = [299, 587, 114]
tmp = sp.inner(tmp, lum) / 1000.0
# normalize per http://en.wikipedia.org/wiki/Cross-correlation
return ((tmp - tmp.mean()) / tmp.std())
示例12: f
def f(self, x):
self.net['mdrnn'].params[:] = x
error = 0
for (inpt, target) in self.trainds:
output = self.net.activate(inpt)
indic = output.reshape(self.width * self.height, 10).sum(axis=0)
diff = indic - target
error += scipy.inner(diff, diff)
return error / len(self.trainds)
示例13: unsigned_volume
def unsigned_volume(pts):
"""Unsigned volume of a simplex
Computes the unsigned volume of an M-simplex embedded in N-dimensional
space. The points are stored row-wise in an array with shape (M+1,N).
Parameters
----------
pts : array
Array with shape (M+1,N) containing the coordinates
of the (M+1) vertices of the M-simplex.
Returns
-------
volume : scalar
Unsigned volume of the simplex
Notes
-----
Zero-dimensional simplices (points) are assigned unit volumes.
Examples
--------
>>> # 0-simplex point
>>> unsigned_volume( [[0,0]] )
1.0
>>> # 1-simplex line segment
>>> unsigned_volume( [[0,0],[1,0]] )
1.0
>>> # 2-simplex triangle
>>> unsigned_volume( [[0,0,0],[0,1,0],[1,0,0]] )
0.5
References
----------
[1] http://www.math.niu.edu/~rusin/known-math/97/volumes.polyh
"""
pts = asarray(pts)
M,N = pts.shape
M -= 1
if M < 0 or M > N:
raise ValueError('array has invalid shape')
if M == 0:
return 1.0
A = pts[1:] - pts[0]
return sqrt(det(inner(A,A)))/factorial(M)
示例14: barycentric_gradients
def barycentric_gradients(pts):
"""
Compute the gradients of the barycentric basis functions over a given simplex
"""
V = asarray(pts[1:] - pts[0])
##all gradients except the first are computed
grads = dot(inv(inner(V,V)),V) #safer, but slower: grads = scipy.linalg.pinv2(V).T
##since sum of all gradients is zero, simply compute the first from the others
return vstack((atleast_2d(-numpy.sum(grads,axis=0)),grads))
示例15: get
def get(pics,i):
#global pics
# get JPG image as Scipy array, RGB (3 layer)
data = imread('%s%d.jpeg' %(pics,i))
data = imresize(data,0.4)
#im2 = imresize(im22,0.5)
#im3 = imresize(im33,0.5)
# convert to grey-scale using W3C luminance calc
data = sp.inner(data, [299, 587, 114]) / 1000.0
# normalize as in http://en.wikipedia.org/wiki/Cross-correlation
return (data - data.mean()) / data.std()