[SciPy-user] SciPy 0.4.4: fromstring

Hugo Gamboa hgamboa at gmail.com
Thu Jan 19 18:06:02 EST 2006


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20060119/f5005fe1/attachment.html>


More information about the SciPy-User mailing list