Integer From A Float List?!?

Discussion in 'Python' started by andrea_gavana@tin.it, Mar 4, 2005.

  1. Guest

    Hello NG,

    I was wondering if there is a way to obtain, from a list of floats,
    a list of integers without loops. Probably is a basic question, but I can't
    find an answer... I have had my eyes blinded by Matlab for years, but now
    that I discovered Python+wxPython there seems to be no limit on what one
    can do with these 2 tools. Anyway, following the Matlab style, I would like
    to do something like this:

    matrix = [1.5, 4.3, 5.5]
    integer_matrix = int(matrix) (float for Matlab)

    (In Matlab, "integer_matrix" is always a double anyway, here I would like
    only to show the vector-matrix operation).

    Obviously, Python complains about:

    Traceback (most recent call last):
    File "<interactive input>", line 1, in ?
    TypeError: int() argument must be a string or a number

    I would like to avoid loops because, having been blinded by Matlab vector-matrix
    abilities (and corresponding SLOW for-while loops operations), I tend to
    think that also Python will be slow if I use loops.

    Does anyone have a suggestion (or maybe could anyone show me that I'm wrong
    about loops?)

    Thanks you a lot.

    Andrea.
    , Mar 4, 2005
    #1
    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. Andy
    Replies:
    7
    Views:
    6,254
    Roedy Green
    May 10, 2004
  2. bd
    Replies:
    0
    Views:
    621
  3. Bill Mill

    Re: Integer From A Float List?!?

    Bill Mill, Mar 4, 2005, in forum: Python
    Replies:
    1
    Views:
    3,687
    George Sakkis
    Mar 5, 2005
  4. Nick Coghlan

    Re: Integer From A Float List?!?

    Nick Coghlan, Mar 5, 2005, in forum: Python
    Replies:
    3
    Views:
    318
    Peter Otten
    Mar 6, 2005
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,533
    James Kanze
    Oct 8, 2009
Loading...

Share This Page