To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
The primary repository for this project is hosted at https://github.com/Codasign/york-software-bootcamp-audio-day.git .
This repository is a read-only copy which is updated automatically every hour.
root / basic-numpy.py @ 1:99434d86405a
History | View | Annotate | Download (1.05 KB)
| 1 |
import numpy as np |
|---|---|
| 2 |
|
| 3 |
|
| 4 |
#################################################
|
| 5 |
############# NUMPY ARRAYS FOR AUDIO? ###########
|
| 6 |
#################################################
|
| 7 |
|
| 8 |
# I am a numpy array containing some audio
|
| 9 |
myAudio = np.array([-0.25,0.0,0.25,0.5]) |
| 10 |
|
| 11 |
# turn it up!
|
| 12 |
myAudio = myAudio*2.
|
| 13 |
|
| 14 |
# great!
|
| 15 |
print myAudio
|
| 16 |
|
| 17 |
|
| 18 |
# what can we find out about our numpy audio?
|
| 19 |
|
| 20 |
|
| 21 |
print "Dimensions: ",myAudio.ndim |
| 22 |
|
| 23 |
print "Size of each dimension: ",myAudio.shape |
| 24 |
|
| 25 |
print "Total number of elements: ", myAudio.size # this is product of shape dimensions |
| 26 |
|
| 27 |
print "Data type: ",myAudio.dtype # ...or dtype.name |
| 28 |
|
| 29 |
print "Bytes per element: ",myAudio.itemsize |
| 30 |
|
| 31 |
print "Second element: ",myAudio[1] |
| 32 |
|
| 33 |
print "All elements up to (but not including) 2: ",myAudio[:2] |
| 34 |
|
| 35 |
print "All elements from index 2 to end: ",myAudio[2:] |
| 36 |
|
| 37 |
print "Abs!: ",np.abs(myAudio) |
| 38 |
|
| 39 |
print "Min: ",np.min(myAudio) |
| 40 |
|
| 41 |
print "Max: ",np.max(myAudio) |
| 42 |
|
| 43 |
print "Sum: ",np.sum(myAudio) |
| 44 |
|
| 45 |
print "Sqrt: ",np.sqrt(9) |
| 46 |
|
| 47 |
print "FFT!: ",np.fft.fft(myAudio) |
| 48 |
|
| 49 |
print "Random!: ",np.random.random(4) |
| 50 |
|
| 51 |
print "Ones: ",np.ones(4) |
| 52 |
|
| 53 |
print "Zeros: ",np.zeros(4) |