data type and logarithm
Peter Otten
__peter__ at web.de
Thu Jun 16 07:55:52 EDT 2011
simona bellavista wrote:
> Hi, I am quite new to python and I am trying to do some simple plots.
> I am using python Python 2.6.4 and numpy/1.5.1
> I have an ASCII data file that I am reading with the following lines
> of code:
>
> import pylab
> import numpy as np
>
> filename='something.dat'
> file = open(filename)
>
> rho = np.array([], dtype = 'float64')
> entropy = np.array([], dtype = 'float64')
> for line in file:
> columns = line.split()
> rho = np.append(rho,columns[0])
You have to convert the string to a float, e. g.
rho = np.append(rho, np.float64(columns[0]))
> entropy = np.append(entropy,columns[1])
>
> and rho and entropy are apparently read correctly, but when I look to
> the data type
>
> print rho.dtype
> print entropy.dtype
>
> I get |S22 , what's that?
> Then I want to plot a logarithmic plot and I do
>
> pylab.plot(np.log(rho), entropy)
>
> and I get
>
> NotImplementedError: Not implemented for this type
>
> Does anybody has a clue? I do not know how to proceed
It should be easier to use numpy.loadtxt():
with open(filename) as f:
a = np.loadtxt(f)
rho = a[..., 0]
entropy = a[..., 1]
More information about the Python-list
mailing list