15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SciPy Reference Guide, Release 0.8.dev<br />

Inputs:<br />

file_name – The complete path name to the file to open<br />

or an open file-like object<br />

permission – Open the file with given permissions: (‘r’, ‘w’, ‘a’)<br />

for reading, writing, or appending. This is the same as the mode argument in<br />

the builtin open command.<br />

format – The byte-ordering of the file:<br />

([’native’, ‘n’], [’ieee-le’, ‘l’], [’ieee-be’, ‘B’]) for native, little-endian, or bigendian<br />

respectively.<br />

Attributes:<br />

endian – default endian code for reading / writing order – default order for reading<br />

writing (‘C’ or ‘F’) file – file object containing read / written data<br />

Methods:<br />

seek, tell, close – as for file objects rewind – set read position to beginning of file<br />

read_raw – read string data from file (read method of file) write_raw – write string<br />

data to file (write method of file) read_array – read numpy array from binary file<br />

data write_array – write numpy array contents to binary file<br />

Example use: >>> from StringIO import StringIO >>> import numpy as np >>> from<br />

<strong>scipy</strong>.io import npfile >>> arr = np.arange(10).reshape(5,2) >>> # Make file-like object<br />

(could also be file name) >>> my_file = StringIO() >>> npf = npfile(my_file)<br />

>>> npf.write_array(arr) >>> npf.rewind() >>> npf.read_array((5,2), arr.dtype) >>><br />

npf.close() >>> # Or read write in Fortran order, Big endian >>> # and read back<br />

in C, system endian >>> my_file = StringIO() >>> npf = npfile(my_file, order=’F’,<br />

endian=’>’) >>> npf.write_array(arr) >>> npf.rewind() >>> npf.read_array((5,2),<br />

arr.dtype)<br />

3.6.4 Wav sound files (<strong>scipy</strong>.io.wavfile)<br />

read(file) Return the sample rate (in samples/sec) and data from a WAV file<br />

write(filename, rate, data) Write a numpy array as a WAV file<br />

read(file)<br />

Return the sample rate (in samples/sec) and data from a WAV file<br />

The file can be an open file or a filename. The returned sample rate is a Python integer The data is returned as a<br />

numpy array with a<br />

data-type determined from the file.<br />

write(filename, rate, data)<br />

Write a numpy array as a WAV file<br />

filename – The name of the file to write (will be over-written) rate – The sample rate (in samples/sec). data – A<br />

1-d or 2-d numpy array of integer data-type.<br />

The bits-per-sample will be determined by the data-type To write multiple-channels, use a 2-d array<br />

of shape (Nsamples, Nchannels)<br />

Writes a simple uncompressed WAV file.<br />

214 Chapter 3. Reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!