[Tutor] (no subject)

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Aug 8 15:45:35 CEST 2013


On 25 July 2013 03:36, Rocko Brown <rokbrown at ucdavis.edu> wrote:
> Hello,
>
> I am trying to generate a 2D histogram for two arrays of data in CSV format.
>
> The code is:
>
> x, y = '5k_vec.csv','tcd_5k.csv'
> H, xedges, yedges = np.histogram2d(x, y)
> H.shape, xedges.shape, yedges.shape

Your using x and y as if they are your data. Presumably your data is
contained in the files '5k_vec.csv' and 'tcd_5k.csv'. However just
writing x = '5k_vec.csv' will not load the data from the file. It just
creates a string with those characters.

Presumably you wanted something like:

with open('5k_vec.csv') as inputfile:
    x = [float(line) for line in inputfile]

(I'm assuming your file just has a number on each line here).

Have a read about files here:
http://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

And the csv module may be helpful too:
http://docs.python.org/3.3/library/csv.html


Oscar


More information about the Tutor mailing list