[Numpy-discussion] using loadtxt to load a text file in to a numpy array
josef.pktd at gmail.com
josef.pktd at gmail.com
Thu Jan 23 15:10:34 EST 2014
On Thu, Jan 23, 2014 at 2:45 PM, Chris Barker <chris.barker at noaa.gov> wrote:
> On Thu, Jan 23, 2014 at 11:18 AM, <josef.pktd at gmail.com> wrote:
>
>>
>> I think this is just inconsistent casting rules in numpy,
>>
>> numpy should either refuse to assign the wrong type, instead of using
>> the repr as in some of the earlier examples of Oscar
>>
>> >>> s = np.inf
>> >>> np.array((s,), dtype=int)[0] == s
>> Traceback (most recent call last):
>> File "<pyshell#126>", line 1, in <module>
>> np.array((s,), dtype=int)[0] == s
>> OverflowError: cannot convert float infinity to integer
>>
>> or use the **same** conversion/casting rules also during the
>> interaction with python as are used in assignments and array creation.
>
>
> Exactly -- but what should those conversion/casting rules be? We can't
> decide that unless we decide if 'S' is for text or for arbitrary bytes -- it
> can't be both. I say text, that's what it's mostly trying to do already. But
> if it's bytes, fine, then some things still need cleaning up, and we could
> really use a one-byte-text type. and if it's text, then we may need a bytes
> dtype.
(remember I'm just a balcony muppet)
As far as I understand all codecs have the same ascii part. So I would
cast on ascii and raise on anything else.
or follow whatever the convention of numpy is:
>>> s = -256
>>> np.array((s,), dtype=np.uint8)[0] == s
False
>>> s = -1
>>> np.array((s,), dtype=np.uint8)[0] == s
False
Josef
>
> Key here is that we don't have the option of not breaking anything, because
> there is a lot already broken.
>
> -Chris
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker at noaa.gov
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list