本文整理汇总了Python中sympy.list2numpy函数的典型用法代码示例。如果您正苦于以下问题:Python list2numpy函数的具体用法?Python list2numpy怎么用?Python list2numpy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了list2numpy函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_conversion2
def test_conversion2():
a = 2*list2numpy([x**2, x])
b = list2numpy([2*x**2, 2*x])
assert (a == b).all()
one = Rational(1)
zero = Rational(0)
X = list2numpy([one, zero, zero])
Y = one*X
X = list2numpy([Symbol("a") + Rational(1, 2)])
Y = X + X
assert Y == array([1 + 2*Symbol("a")])
Y = Y + 1
assert Y == array([2 + 2*Symbol("a")])
Y = X - X
assert Y == array([0])
示例2: test_conversion1
def test_conversion1():
a = list2numpy([x**2, x])
#looks like an array?
assert isinstance(a, ndarray)
assert a[0] == x**2
assert a[1] == x
assert len(a) == 2
示例3: tonumpy
def tonumpy(array,units):
""" Convert to numpy aa sympy number, a sympy array, or a python array of sympy numbers.
>>> print tonumpy(units.GeV, units.MeV)
1000.0
>>> print tonumpy(tosympy([1],units.GeV),units.MeV)
[ 1000.]
>>> print tonumpy([1*units.GeV],units.MeV)
[ 1000.]
"""
try:
if isinstance(array,list):
return np.asarray([float(i/units) for i in array])
if hasattr(array,'shape'):
return sympy.list2numpy(array/units).astype(float)
else:
return float(array/units)
except:
raise UnitsException("Unable to convert array %s to units %s." % (array,units))
示例4: test_list2numpy
def test_list2numpy():
assert (array([x**2, x]) == list2numpy([x**2, x])).all()
示例5: test_list2numpy
def test_list2numpy():
x = Symbol("x")
assert (array([x**2, x]) == list2numpy([x**2, x])).all()