[Numpy-discussion] unpacking data values into array of bits
Neal Becker
ndbecker2 at gmail.com
Thu Feb 12 10:22:08 EST 2015
Robert Kern wrote:
> On Thu, Feb 12, 2015 at 3:00 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
>>
>> Robert Kern wrote:
>>
>> > On Thu, Feb 12, 2015 at 2:21 PM, Neal Becker <ndbecker2 at gmail.com>
> wrote:
>> >>
>> >> I need to transmit some data values. These values will be float and
> long
>> >> values. I need them encoded into a string of bits.
>> >>
>> >> The only way I found so far to do this seems rather roundabout:
>> >>
>> >>
>> >> np.unpackbits (np.array (memoryview(struct.pack ('d', pi))))
>> >> Out[45]:
>> >> array([0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0,
> 1,
>> > 0,
>> >> 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0,
> 0,
>> > 0,
>> >> 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
> dtype=uint8)
>> >>
>> >> (which I'm not certain is correct)
>> >>
>> >> Also, I don't know how to reverse this process
>> >
>> > You already had your string ready for transmission with
> `struct.pack('d',
>> > pi)`.
>> >
>> > --
>> > Robert Kern
>>
>> my transmitter wants an np array of bits, not a string
>
> Can you provide any details on what your "transmitter" is?
>
> --
My transmitter is c++ code that accepts as input a numpy array of np.int32.
Each element of that array has value 0 or 1.
More information about the NumPy-Discussion
mailing list