[SciPy-user] NumPy Newcomer Questions: Reading Data Stream & Building Array

Johannes Loehnert a.u.r.e.l.i.a.n at gmx.net
Fri Sep 8 18:06:40 CDT 2006


Hi,

>    The data format is a stream of ASCII bytes. Each two-byte combination
> represents either a string (for two columns) or an integer (for the other
> 28 data columns). The conversion from position-specific bit values to the
> ASCII characters is accomplished using the data mapping dictionaries. I
> accept that I wasn't as clear as I could have been.

Understood now. But you cannot store strings and floats in an array 
simultaneously.

>    After sending the message it occurred to me that the string.Split()
> function is probably what I want. I'm not receiving Hex values from the
> scanner. I'll play with this over the weekend.

Not sure about string.split(), I don't think this is useful (would split into 
1-byte chars iirc). You can you use a list comprehension for the data part, 
like this:

line = read_data()
mapped_vals = [DATA_MAP_7[i:i+2] for i in range(2*7, 2*35)]

although I admit it is no very pretty solution. Maybe somebody has a better 
idea.

>    You are correct, however, that I do want to take that incoming string
> and store it into an array in the fewest possible steps. I'll have to look
> at 'fromstring()' to see just what that does. I assumed that each row in
> the array was a list, is that incorrect?

well, since the data has to be mapped in a certain manner first, I'm not sure 
if fromstring() really helps here. I did not realize this at the first 
glance.


BTW, while having a closer look to your code I noticed that at line 72 ("line 
= ser.readline") there is a pair of brackets missing. Here is one free of 
charge: ()
;-)

Johannes


More information about the SciPy-user mailing list