本文整理汇总了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)