Numeric - Multiply a byte array by a float.

Discussion in 'Python' started by Kamilche, Jul 14, 2004.

  1. Kamilche

    Kamilche Guest

    I have a need to multiply all the bytes in a Numeric array, by a
    float, such as .9, .8, etc. I can't figure out a way to do that.

    Does anyone have a clue how this is accomplished? I need the resulting
    array to be truncated to an array of bytes.

    Thanks!

    --Kamilche
    Kamilche, Jul 14, 2004
    #1
    1. Advertising

  2. On 13 Jul 2004, Kamilche wrote:

    > I have a need to multiply all the bytes in a Numeric array, by a
    > float, such as .9, .8, etc. I can't figure out a way to do that.


    By "all the bytes in a Numeric array", I'm assuming you mean you have an
    Int8 or UInt8 array. Correct me if I'm wrong.

    > Does anyone have a clue how this is accomplished? I need the resulting
    > array to be truncated to an array of bytes.


    This should work, assuming my above assumption is correct:

    byte_array = array([1,2,3,4,5,6],Int8)
    byte_array = (byte_array*.5).astype(Int8)
    Christopher T King, Jul 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kirby
    Replies:
    3
    Views:
    611
    Kirby
    Oct 8, 2004
  2. bd
    Replies:
    0
    Views:
    594
  3. Zhang Le
    Replies:
    1
    Views:
    353
    Terry Reedy
    Mar 4, 2005
  4. Replies:
    5
    Views:
    560
    Christian Bau
    Sep 1, 2005
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,483
    James Kanze
    Oct 8, 2009
Loading...

Share This Page