Member Avatar for tottletj

Basically I've looked everywhere for help with this problem and been unable to find any so i thought i'd ask here.
I have a text file full of numbers which i wish to manipulate.
the actual text file has about 200 rows and 10 columns, but in this example i'll just pretend i have a text file that contains the following:
85.6 0.1 555.78
67.9 0.7 869.42
45.2 0.1 654.79
102.8 1.3 916.94

so i have 12 floats in this file, arranged into 3 columns and 4 rows with an arbitrary number of spaces inbetween each number.

Now I want python to read this, somehow realise it has 3 columns and 4 rows and put it into a 4 by 3 array (array[4,3]), so i can then manipulate this array

I'm not very skilled with python (Ive been using it on/off for a couple of years) so my knowledge isn't very extensive. I've got python to open and read the file but i cant seem to make it do anything useful with the numbers inside.

Any help would be appreciated.

Use

array = [[float(x) for x in line.strip().split()] for line in open("file.txt")]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.