Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7730 > unrolled thread
| Started by | simona bellavista <afylot@gmail.com> |
|---|---|
| First post | 2011-06-16 01:37 -0700 |
| Last post | 2011-06-16 16:21 -0500 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.lang.python
data type and logarithm simona bellavista <afylot@gmail.com> - 2011-06-16 01:37 -0700
Re: data type and logarithm Nobody <nobody@nowhere.com> - 2011-06-16 10:16 +0100
Re: data type and logarithm "afylot@gmail.com" <antonella.garzilli@gmail.com> - 2011-06-16 02:27 -0700
Re: data type and logarithm Peter Otten <__peter__@web.de> - 2011-06-16 13:55 +0200
Re: data type and logarithm Terry Reedy <tjreedy@udel.edu> - 2011-06-16 13:20 -0400
Re: data type and logarithm Robert Kern <robert.kern@gmail.com> - 2011-06-16 16:21 -0500
| From | simona bellavista <afylot@gmail.com> |
|---|---|
| Date | 2011-06-16 01:37 -0700 |
| Subject | data type and logarithm |
| Message-ID | <b583dac8-826e-4bd5-b230-00e667855896@m24g2000yqc.googlegroups.com> |
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])
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
Many thanks
[toc] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-06-16 10:16 +0100 |
| Message-ID | <pan.2011.06.16.09.16.11.16000@nowhere.com> |
| In reply to | #7730 |
On Thu, 16 Jun 2011 01:37:08 -0700, simona bellavista wrote: > print rho.dtype > print entropy.dtype > > I get |S22 , what's that? A string. You probably want to convert "columns" to floats before appending its elements to the array.
[toc] | [prev] | [next] | [standalone]
| From | "afylot@gmail.com" <antonella.garzilli@gmail.com> |
|---|---|
| Date | 2011-06-16 02:27 -0700 |
| Message-ID | <7c00ab68-8afa-4175-b077-4a949ebf41fb@m10g2000yqd.googlegroups.com> |
| In reply to | #7731 |
I tried to cast it to float by rho = float(np.append(rho,columns[0])) but I get TypeError: don't know how to convert scalar number to float By the way, if I avoid to perform the logarithm and do a plot like pylab.plot(rho, entropy) it works! Any idea? On Jun 16, 11:16 am, Nobody <nob...@nowhere.com> wrote: > A string. You probably want to convert "columns" to floats before > appending its elements to the array.
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2011-06-16 13:55 +0200 |
| Message-ID | <itcqv0$nfj$1@solani.org> |
| In reply to | #7730 |
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]
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2011-06-16 13:20 -0400 |
| Message-ID | <mailman.25.1308244859.1164.python-list@python.org> |
| In reply to | #7730 |
On 6/16/2011 4:37 AM, 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)
combine into one statement
file = open("sjlsjls.dat")
> rho = np.array([], dtype = 'float64')
> entropy = np.array([], dtype = 'float64')
> for line in file:
> columns = line.split()
r,e = line.split()
> rho = np.append(rho,columns[0])
> entropy = np.append(entropy,columns[1])
rho = mp.append(rho, float(r)) # same with entropy)
does numpy really not let you write Python stype
rho.append(float(r))
?
There are also numpy,scipy lists for numpy,scipy questions.
--
Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2011-06-16 16:21 -0500 |
| Message-ID | <mailman.42.1308259331.1164.python-list@python.org> |
| In reply to | #7730 |
On 6/16/11 12:20 PM, Terry Reedy wrote: > rho = mp.append(rho, float(r)) # same with entropy) > > does numpy really not let you write Python stype > > rho.append(float(r)) > ? No. numpy arrays are not extensible in-place in general because we use view semantics for slices and similar operations like transpositions. We can't have the underlying memory change out from underneath us. This is one of the worst ways to accumulate values into a numpy array. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web