本文整理汇总了Python中numpy.lib.type_check.iscomplex函数的典型用法代码示例。如果您正苦于以下问题:Python iscomplex函数的具体用法?Python iscomplex怎么用?Python iscomplex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iscomplex函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __str__
def __str__(self):
thestr = "0"
var = self.variable
# Remove leading zeros
coeffs = self.coeffs[NX.logical_or.accumulate(self.coeffs != 0)]
N = len(coeffs)-1
def fmt_float(q):
s = '%.4g' % q
if s.endswith('.0000'):
s = s[:-5]
return s
for k in range(len(coeffs)):
if not iscomplex(coeffs[k]):
coefstr = fmt_float(real(coeffs[k]))
elif real(coeffs[k]) == 0:
coefstr = '%sj' % fmt_float(imag(coeffs[k]))
else:
coefstr = '(%s + %sj)' % (fmt_float(real(coeffs[k])),
fmt_float(imag(coeffs[k])))
power = (N-k)
if power == 0:
if coefstr != '0':
newstr = '%s' % (coefstr,)
else:
if k == 0:
newstr = '0'
else:
newstr = ''
elif power == 1:
if coefstr == '0':
newstr = ''
elif coefstr == 'b':
newstr = var
else:
newstr = '%s %s' % (coefstr, var)
else:
if coefstr == '0':
newstr = ''
elif coefstr == 'b':
newstr = '%s**%d' % (var, power,)
else:
newstr = '%s %s**%d' % (coefstr, var, power)
if k > 0:
if newstr != '':
if newstr.startswith('-'):
thestr = "%s - %s" % (thestr, newstr[1:])
else:
thestr = "%s + %s" % (thestr, newstr)
else:
thestr = newstr
return _raise_power(thestr)
开发者ID:MarkNiemczyk,项目名称:numpy,代码行数:56,代码来源:polynomial.py
示例2: __str__
def __str__(self):
thestr = "0"
var = self.variable
# Remove leading zeros
coeffs = self.coeffs[NX.logical_or.accumulate(self.coeffs != 0)]
N = len(coeffs) - 1
def fmt_float(q):
s = "%.4g" % q
if s.endswith(".0000"):
s = s[:-5]
return s
for k in range(len(coeffs)):
if not iscomplex(coeffs[k]):
coefstr = fmt_float(real(coeffs[k]))
elif real(coeffs[k]) == 0:
coefstr = "%sj" % fmt_float(imag(coeffs[k]))
else:
coefstr = "(%s + %sj)" % (fmt_float(real(coeffs[k])), fmt_float(imag(coeffs[k])))
power = N - k
if power == 0:
if coefstr != "0":
newstr = "%s" % (coefstr,)
else:
if k == 0:
newstr = "0"
else:
newstr = ""
elif power == 1:
if coefstr == "0":
newstr = ""
elif coefstr == "b":
newstr = var
else:
newstr = "%s %s" % (coefstr, var)
else:
if coefstr == "0":
newstr = ""
elif coefstr == "b":
newstr = "%s**%d" % (var, power)
else:
newstr = "%s %s**%d" % (coefstr, var, power)
if k > 0:
if newstr != "":
if newstr.startswith("-"):
thestr = "%s - %s" % (thestr, newstr[1:])
else:
thestr = "%s + %s" % (thestr, newstr)
else:
thestr = newstr
return _raise_power(thestr)
开发者ID:RenanGreca,项目名称:wireless-networks,代码行数:55,代码来源:polynomial.py
示例3: test_pass
def test_pass(self):
z = np.array([-1j, 1, 0])
res = iscomplex(z)
assert_array_equal(res, [1, 0, 0])
开发者ID:dyao-vu,项目名称:meta-core,代码行数:4,代码来源:test_type_check.py
示例4: test_fail
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
开发者ID:dyao-vu,项目名称:meta-core,代码行数:4,代码来源:test_type_check.py
注:本文中的numpy.lib.type_check.iscomplex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论