I want to add a number of variables which I have no control over to a numpy array. I want to do something like:
def f(x, y):assert_homogeneous(x, y)a = array([x, y])
however, I would also like to move the unit "outside" of the array as proposed in the tutorial to gain some speed. The above construction will fill the array with Quantity objects. But I find no way to do thing. I have so far done:
def f(x, y):assert_homogeneous(x, y)d = x/value(x)a = array([x/d, y/d])
and this kindo works as long as x is not 0, a i now a float64 array. However, now I need to add the dimension, but doing
a = d*a
raises an exception:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\formatters.py", line 672, in call
printer.pretty(obj)
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\lib\pretty.py", line 383, in pretty
return _default_pprint(obj, self, cycle)
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\lib\pretty.py", line 503, in _default_pprint
_repr_pprint(obj, p, cycle)
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\lib\pretty.py", line 701, in _repr_pprint
output = repr(obj)
File "C:\ProgramData\Anaconda3\lib\site-packages\natu\core.py", line 824, in repr
return format(self, 'g')
File "C:\ProgramData\Anaconda3\lib\site-packages\natu\core.py", line 372, in wrapped
return meth(self / unit, number_code, unit_code) + unit_str
File "C:\ProgramData\Anaconda3\lib\site-packages\natu\core.py", line 810, in format
number_str = format_e(format(number, number_code), unit_code)
TypeError: unsupported format string passed to numpy.ndarray.format
doing
a = a*d
works, but then the unit ends up on every element again. Any suggestions?
I want to add a number of variables which I have no control over to a numpy array. I want to do something like:
def f(x, y):
assert_homogeneous(x, y)
a = array([x, y])
however, I would also like to move the unit "outside" of the array as proposed in the tutorial to gain some speed. The above construction will fill the array with Quantity objects. But I find no way to do thing. I have so far done:def f(x, y):
assert_homogeneous(x, y)
d = x/value(x)
a = array([x/d, y/d])
and this kindo works as long as x is not 0, a i now a float64 array. However, now I need to add the dimension, but doinga = d*a
raises an exception: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\formatters.py", line 672, in call printer.pretty(obj) File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\lib\pretty.py", line 383, in pretty return _default_pprint(obj, self, cycle) File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\lib\pretty.py", line 503, in _default_pprint _repr_pprint(obj, p, cycle) File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\lib\pretty.py", line 701, in _repr_pprint output = repr(obj) File "C:\ProgramData\Anaconda3\lib\site-packages\natu\core.py", line 824, in repr return format(self, 'g') File "C:\ProgramData\Anaconda3\lib\site-packages\natu\core.py", line 372, in wrapped return meth(self / unit, number_code, unit_code) + unit_str File "C:\ProgramData\Anaconda3\lib\site-packages\natu\core.py", line 810, in format number_str = format_e(format(number, number_code), unit_code) TypeError: unsupported format string passed to numpy.ndarray.format doinga = a*d
works, but then the unit ends up on every element again. Any suggestions?