|
From: Scott D. D. <Sco...@Ac...> - 2007-12-27 16:34:07
|
Bruce Sherwood wrote:
> I've already played with essentially this. In
> site-packages/visual/__init__.py we import math, then numpy, which means
> that sqrt goes to numpy. If I reverse the order of these imports it does
> indeed mean that we use math.sqrt, but this then breaks programs such as
> gas.py where the argument of the sqrt is an array of vectors. What I
> need is for sqrt(25) to be treated like 5, but also to be able to use
> the array features of the numpy sqrt when the argument isn't a simple
> scalar.
I'm not sure of the overhead here, but could something like this work?
def sqrt(x):
try: return math.sqrt(x)
except TypeError: return numpy.sqrt(x)
--Scott David Daniels
Sco...@Ac...
|