[Numpy-discussion] switching to float32
Sat Jun 27 19:31:21 CDT 2009
Dag Sverre Seljebotn wrote:
> Well, such a mechanism would mean that your code could not be reused
> reliably by other code (because, what if two different codebases sets
> different defaults...). So requiring any such mechanism would make it
> easier to write non-reusable code, which is generally considered a bad
> Note that it is relatively easy for you to do e.g.
> default_dtype = np.float32
> def array(*args, **kw):
> if 'dtype' not in kw.keys():
> return np.array(*args, **kw, dtype=default_dtype)
> return np.array(*args, **kw)
> and so on in your own codebase, avoiding the problem.
Neat trick - I think I'll do exactly that. I'll also need to cover a few
other cases, like zeros(), ones(), etc., but I think it should work. One
could even write a little macro that generates wrappers like this for
all numpy/scipy functions that have a 'dtype' argument.
Thanks for an excellent idea!
More information about the Numpy-discussion