Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-05 Thread Gregorio Bastardo
Hi Stéfan, I ran into a problem: min_typecode( (18446744073709551615L,) ) # ok type 'numpy.uint64' min_typecode( (0, 18446744073709551615L,) ) # ? Traceback (most recent call last): ... ValueError: Can only handle integer arrays. It seems that np.asarray converts the input sequence into a

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-04 Thread Gregorio Bastardo
@Stéfan: the 'np.all' calls are now unnecessary on line 26 @Stéfan, Robert: Is it worth to bring this solution into numpy? I mean it's probably not a rare problem, and now users have to bring this snippet into their codebase. Gregorio 2013/9/3 Stéfan van der Walt ste...@sun.ac.za: On Tue, Sep

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-03 Thread Gregorio Bastardo
Thanks Stéfan, your script works well. There's a small typo on line 12. I also discovered the functions 'np.iinfo' and 'np.finfo' for machine limits on integer/float types (a note for myself, you might be already familiar with them). After having read the docstring, I was only curious why this

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-03 Thread Robert Kern
On Mon, Sep 2, 2013 at 3:55 PM, Stéfan van der Walt ste...@sun.ac.za wrote: On Mon, Sep 2, 2013 at 4:21 PM, Gregorio Bastardo gregorio.basta...@gmail.com wrote: np.min_scalar_type([-1,256]) # int16 expected dtype('int32') Am I missing something? Anyone knows how to achieve the desired

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-03 Thread Stéfan van der Walt
On Tue, Sep 3, 2013 at 2:47 PM, Robert Kern robert.k...@gmail.com wrote: Here's one way of doing it: https://gist.github.com/stefanv/6413742 You can probably reduce the amount of work by only comparing a.min() and a.max() instead of the whole array. Thanks, fixed. Stéfan

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-02 Thread Stéfan van der Walt
On Mon, Sep 2, 2013 at 4:21 PM, Gregorio Bastardo gregorio.basta...@gmail.com wrote: np.min_scalar_type([-1,256]) # int16 expected dtype('int32') Am I missing something? Anyone knows how to achieve the desired operation? The docstring states explicitly that this use case is not supported.