本文整理匯總了Python中numpy.lib.function_base._parse_gufunc_signature方法的典型用法代碼示例。如果您正苦於以下問題:Python function_base._parse_gufunc_signature方法的具體用法?Python function_base._parse_gufunc_signature怎麽用?Python function_base._parse_gufunc_signature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.lib.function_base
的用法示例。
在下文中一共展示了function_base._parse_gufunc_signature方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_parse_gufunc_signature
# 需要導入模塊: from numpy.lib import function_base [as 別名]
# 或者: from numpy.lib.function_base import _parse_gufunc_signature [as 別名]
def test_parse_gufunc_signature(self):
assert_equal(nfb._parse_gufunc_signature('(x)->()'), ([('x',)], [()]))
assert_equal(nfb._parse_gufunc_signature('(x,y)->()'),
([('x', 'y')], [()]))
assert_equal(nfb._parse_gufunc_signature('(x),(y)->()'),
([('x',), ('y',)], [()]))
assert_equal(nfb._parse_gufunc_signature('(x)->(y)'),
([('x',)], [('y',)]))
assert_equal(nfb._parse_gufunc_signature('(x)->(y),()'),
([('x',)], [('y',), ()]))
assert_equal(nfb._parse_gufunc_signature('(),(a,b,c),(d)->(d,e)'),
([(), ('a', 'b', 'c'), ('d',)], [('d', 'e')]))
with assert_raises(ValueError):
nfb._parse_gufunc_signature('(x)(y)->()')
with assert_raises(ValueError):
nfb._parse_gufunc_signature('(x),(y)->')
with assert_raises(ValueError):
nfb._parse_gufunc_signature('((x))->(x)')
示例2: transform
# 需要導入模塊: from numpy.lib import function_base [as 別名]
# 或者: from numpy.lib.function_base import _parse_gufunc_signature [as 別名]
def transform(self, X):
if self.func is None:
return X
if self.signature:
input_dims, output_dims = _parse_gufunc_signature(
signature=self.signature)
else:
input_dims, output_dims = [()], [()]
# This below ensures FeatureUnion's concatenation (hstack) does not fail
# because of resulting arrays having different number of dims
if len(input_dims[0]) == 1 and len(output_dims[0]) == 0:
X = np.expand_dims(X, axis=1) # Add one extra dimension if (n)->()
elif len(input_dims[0]) == 0 and len(output_dims[0]) == 1:
X = np.squeeze(X, axis=1) # Remove singleton dimension if ()->(n)
return np.vectorize(self.func, otypes=[np.float], signature=self.signature)(
X)