On 7 June 2017 at 00:05, Chris Barker wrote:
> On Mon, Jun 5, 2017 at 3:59 PM, Mikhail V wrote:
>> s= "012 abc"
>> B = bytes(s.encode()) # convert to bytes
>> k = len(s)
>> arr = np.zeros(k,"u1") # init empty array length k
>> arr[0:2] = list(B[0:2])
>> print ("my array: ", arr)
>> ->
>> my
On Mon, Jun 5, 2017 at 4:06 PM, Mikhail V wrote:
> Likely it was about some new string array type...
yes, it was.
> Obviously there is demand. Terror of unicode touches many aspects
> of programmers life.
I don't know that I'd call it Terror, but frankly, the fact that you need
up to 4 byte
On Mon, Jun 5, 2017 at 3:59 PM, Mikhail V wrote:
> -- classify by "forward/backward" conversion:
> For this time consider only forward, i.e. I copy data from string
> to numpy array
>
> -- classify by " bytes vs ordinals ":
>
> a) bytes: If I need raw bytes - in this case e.g.
>
> B = b
On 5 June 2017 at 19:40, Chris Barker wrote:
>
>
>> > Python3 assumes 4-byte strings but in reality most of the time
>> > we deal with 1-byte strings, so there is huge waste of resources
>> > when dealing with 4-bytes. For many serious projects it is just not
>> > needed.
>>
>> That's quite enough
On 4 June 2017 at 23:59, Thomas Jollans wrote:
>
>
> For what it's worth, in Python 3 (which you probably should want to be
> using), everything behaves as you'd expect:
>
import numpy as np
s = b'012 abc'
a = np.fromstring(s, 'u1')
a
> array([48, 49, 50, 32, 97, 98, 99], dtype
On Mon, Jun 5, 2017 at 1:51 PM, Thomas Jollans wrote:
> > and overloading fromstring() to mean both "binary dump of data" and
> > "parse the text" due to whether the sep argument is set was always a
> > bad idea :-(
> >
> > .. and fromstring(s, sep=a_sep_char)
>
> As it happens, this is pretty mu
On 05/06/17 19:40, Chris Barker wrote:
>
> If you ask me, passing a unicode string to fromstring with sep=''
> (i.e.
> to parse binary data) should ALWAYS raise an error: the semantics only
> make sense for strings of bytes.
>
>
> exactly -- we really should have a "frombytes()" ali
Just a few notes:
However, the fact that this works for bytestrings on Python 3 is, in my
> humble opinion, ridiculous:
>
> >>> np.array(b'100', 'u1') # b'100' IS NOT TEXT
> array(100, dtype=uint8)
>
Yes, that is a mis-feature -- I think due to bytes and string being the
same object in py2 -- so
On 04/06/17 20:04, Mikhail V wrote:
> Initialize array from a string currently looks like:
>
> s= "012 abc"
> A= fromstring(s,"u1")
> print A ->
> [48 49 50 32 97 98 99]
>
> Perfect.
> Now when writing values it will not work
> as IMO it should, namley consider this example:
>
> B= zeros(7,"u1")
>
Array and string interoperability
Just sharing my thoughts and few ideas about simplification of casting
strings to arrays.
In examples assume Numpy is in the namespace (from numpy import *)
Initialize array from a string currently looks like:
s= "012 abc"
A= fromstring(s,"u1")
print A ->
[48 49
10 matches
Mail list logo