473,785 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: maximum value in a column of file

maurizio wrote:
i tryed to use the module max of numpy,
the problem is that i don't know how to put the column of the file in an
array.
(i'm new in phyton).
anyway if you think there is a better way.....
What kind of file is it? Did you pick numpy because you want to do
matrix operations (beyond just finding a maximum value), or was it just
the first thing you stumbled upon when researching the problem?

A simple pattern for finding the maximum value in a file, using only
plain Python code, is:

max_value = ... some very small value ...
for line in file:
value = ... extract value from line ...
if value max_value:
max_value = value

If it's not obvious what "some very small value" is, given the range of
data you're working with, you can do

max_value = None
for line in file:
value = ... extract value from line ...
if max_value is None or value max_value:
max_value = value

instead (this leaves max_value set to None if the file is empty)

A more experienced Python hacker might write

def get_all_values( file):
for line in file:
value = ... extract value from line ...
yield value

...

max_value = max(get_all_val ues(file))

instead. But this still leaves us with the problem of extracting the
value. The best way to do that depends on the kind of files you're
working with; for fixed-format text files, you could use string slicing
and int/float for conversion (e.g. "value = float(line[10:20])", see the
tutorial for details); for other text formats, you could use
split/partition or regular expressions, or maybe an existing module
(such as "csv"); for binary formats, there's a large
number of existing tools.

And if you really want to use numpy for other reasons than just getting
a maximum value from a column, there's plenty of stuff in NumPy and
SciPy (http://www.scipy.org/) that might be useful.

So, in other words, I guess we still need more info.

</F>

Jul 23 '08 #1
0 1541

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

Similar topics

4
6860
by: Joe Goh | last post by:
Hi there Does anyone know what is the maximum column length for a table in a MySQL database? I was thinking of storing feedback in the form of text in the database. How feasible is this? Would appreciate any insights or suggestions. Thank you again Joe
2
1914
by: Hennie de Nooijer | last post by:
I have a problem (who not?) with a function which i'm using in a view. This function is a function which calculates a integer value of a date. For example: '12/31/2004 00:00:00" becomes 20041231. This is very handy in a datawarehouse and performes superfast. But here is my problem. My calendar table is limited by a couple of years. What happens is that sometimes a value is loaded which is not in the range of the Calendardate. What we...
2
2336
by: Hennie de Nooijer | last post by:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message. -------------------------------------REPY---------------------------------- Hi Maybe i wasn't clear. I want to dynamically check whether what the lowest date and the highest date is in the calendar table. The presented solutions has fixed dates and i don't want that. If i could store a global...
2
10352
by: Roger Withnell | last post by:
How do I find the maximum value of a recordset column? I'd rather do it this way than open a new recordset with Max(column). Thanks in anticipation. Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
2
28600
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
1
1104
by: maurizio | last post by:
which is the best way for the calculation of the maximum value in a column of a file?
1
3374
by: maurizio | last post by:
thank you for your answer actually i've to do some statistics (maximum,minimum,mean,standard deviation,....) of a file of data in which each column is a particular type of data. (the file is a tab separated value). I was trying to do this by using python (usually i work with fortran or bash, but i'm learning python), that the reason why i tried to use numpy. Fredrik Lundh wrote:
1
208
by: Fredrik Lundh | last post by:
maurizio wrote: As I implied, you can do all this in standard Python "by hand", but numpy/scipy can definitely make things easier. There's a dependency cost here (your program needs one or more extra libraries to work), but if that's no problem in your environment, I'd recommend that approach. The scipy add-on contains a bunch of things for file i/o; see
7
7001
by: laredotornado | last post by:
Hi, I'm using PHP 5 with MySql 5. I have a MySQL InnoDB table with a column of type INTEGER UNSIGNED. Is there a constant in PHP to insert the maximum value possible into the column? The underlying OS is Red Hat Linux, but I'm not sure about the version. Any help you can provide is appreciated, - Dave
0
10350
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.