From: Bruce S. <Bru...@nc...> - 2007-12-26 23:45:24
|
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. A related issue is that VPython is deliberately designed to be easily usable by novice users, with sensible defaults, and without the necessity of special imports or references to differences between math and numpy. And maybe even more to the point, the change from Numeric to numpy has made many existing programs run much more slowly than before. But thanks for the suggestion! Bruce Scott David Daniels wrote: > Bruce Sherwood wrote: > >> There is a highly technical problem which has been identified but for >> which there is currently no known solution. In the old Numeric module >> used in Visual 3, sqrt(5.5) was a float, but in numpy used in the beta >> version sqrt(5.5) is numpy.float64, with the highly unfortunate result >> that sqrt(5.5)*vector isn't a VPython vector but rather a numpy array. >> > If you use the simple expedient of using math.sqrt, rather than > numpy.sqrt, you will have the behavior you prefer. The "ufunc"s in > numpy that have corresponding functions in math are: > ceil cos cosh exp fabs floor fmod frexp hypot > ldexp log log10 modf sin sinh sqrt tan tanh > > So adding: > from math import (ceil, cos, cosh, exp, fabs, floor, fmod, frexp, > hypot, ldexp, log, log10, modf, sin, sinh, sqrt, tan, tanh) > after importing numpy (or the moral equivalent) will give you scalar- > producing and consuming functions, as opposed to the numpy-internal > floating format. > > -Scott David Daniels > Sco...@Ac... > > > |