[SciPy-user] SciPy 0.4.4: fromstring

José María josemaria.alkala at gmail.com
Fri Jan 20 09:39:46 CST 2006


Sorry me, I was wrong. There wan't the function "fromstring" the origin of the 
problem. But it was fine to learn about "fromfile". Thanks a lot.
Kind regards,
Jose María

On Friday 20 January 2006 00:06, Hugo Gamboa wrote:
> I'm using the method fromfile  that reads the file directly, and works
> impressively fast.
>
> To you really need to read the file as a string, and then convert it?
>
> The following code shows the timing of fromstring and fromfile in a file
> with 80mb (the difference is only visible with large files)
>
>  from  scipy import *import timingimport  os*def* tic():
>     timing.start()
> *def*  tac(s=""):
>     timing.finish()
>     *print*(str(timing.milli())+'ms '+s)
>
>
> tic()
> a=randn(10000,1000)
> tac("Generate data")
>
> tic()
> f=open("tofile.mat","w")a.tofile(f)
> tac("Write tofile")
>
> tic()
> f=open("tofile.mat","r")
> d=fromfile(f,"d")
> tac("Read fromfile")
>
> tic()
> f=open("tofile.mat","r")
> l=f.read()
> d=fromstring(l,"d")
> tac("read fromstring")
> os.remove("tofile.mar")
>
>
>
> Hugo Gamboa
>
> On 1/19/06, José María <josemaria.alkala at gmail.com> wrote:
> > Hello,
> > I have changed to SciPy 0.4.4 but now, the next code for reading
> > audiofiles:
> > -------------------------------------------------
> > def ReadRawSound (_filename):
> >         _fSound = open( _filename , 'r' )
> >         _SoundAsChar = _fSound.read()
> >         _fSound.close()
> >         _SoundAsFloat = scipy.fromstring( _SoundAsChar , dtype='f' ,
> > count=-1)
> >
> >         return _SoundAsFloat
> > --------------------------------------------------
> >
> > With the previous version I used:
> > _SoundAsFloat =scipy.fromstring( _SoundAsChar , typecode='f' , count=-1)
> >
> > The problem is that now this function seems VERY slow.
> >
> > ===============================
> > I'm using Gentoo and I'm really new to python and scipy. There still no
> > exist
> > and ebuild so I installed by doing:
> > python setup.py build
> > python setup.py install
> >
> >
> > Is this a problem with 'fromstring' or with my installation?
> >
> > Thanks a lot in advance?
> > José María (Spain)
> >
> >
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user at scipy.net
> > http://www.scipy.net/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list