473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Integer From A Float List?!?

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.

Jul 18 '05 #1
0 1259

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lkrubner | last post by:
I just noticed this when I was catching up on old posts: >Senator Jay Billington Bulworth Feb 3, 6:09 am >function getmicrotime(){ > list($usec, $sec) = explode(' ', microtime()); > ...
0
by: andrea_gavana | last post by:
Hello NG, probably because I still have Python 2.3.4, these are the results I'm getting: C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints = m ap(int, floats)"...
1
by: Bell, Kevin | last post by:
I'm pulling a range of cells from Excel into a list and the data in Excel is a number or possibly some text like an asterisk. Each member of the list is a com object (I think) and I'm converting...
9
by: Darius Fatakia | last post by:
hi, i'm new to MS Visual Studio and C++ but not to C programming in general. i'm trying to divide two integers and get their actual quotient (eg 5/3 = 1.666667 etc). i thought i had type cast...
8
by: Brent Lievers | last post by:
Greetings, I have a question about parsing a fixed-width integer from a string. Lines of data are being read from a file having a very strict column-delimited format. In my example below,...
6
by: J.Marsch | last post by:
Suppose that I have an integer division problem, but I want the answer was a float. What's the cleanest syntax for that? Example: In this code, the variable z ends up == 0. And that is...
21
by: Karl O. Pinc | last post by:
FYI, It'd be nice if the error message from a REFERENCES constraint mentioned the column name into which the bad data was attempted to be inserted. In PostgreSQL 7.3: sandbox=> insert into...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
21
by: no1zson | last post by:
I do not even know how to correctly ask this question. I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number. Over the...
16
by: skanemupp | last post by:
which is the best way to check if a string is an number or a char? could the 2nd example be very expensive timewise if i have to check a lot of strings? this value = raw_input() try:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.