Python Sine function error
Question: I have worked for a while in matlab but want now also learn some python. but
after a few days i run in some trouble...

I have similar functions. one matplotlib example and one own based on some
examples (probably also the matplotlib one)

The trouble is that one function is working one not...

This one is working

    
    
    import matplotlib.pylab
    from pylab import *
    
    t = arange(0.0, 2.0, 0.01)
    s = sin(2*pi*t)
    plot(t, s)
    
    xlabel('time (s)')
    ylabel('voltage (mV)')
    title('About as simple as it gets, folks')
    grid(True)
    savefig("test.png")
    show()
    

This one

    
    
    import math
    import numpy
    #import scipy
    import matplotlib.pylab as plt
    
    f0 = 50
    f1 = 500 
    t1 = 2
    t = numpy.arange(0,t1,1/44100)#[numpy.newaxis]; 
    #print(t.getshape())
    
    sine = math.sin(2*math.pi*f0*t)
    
    plt.plot(t, sine)
    plt.xlabel('Angle [rad]')
    plt.ylabel('sin(t)')
    plt.axis('tight')
    plt.show()
    

gives the following error

> File "C:/Users/location/test_sweep.py", line 19, in sine =
> math.sin(2*math.pi*f0*t)
>
> TypeError: only length-1 arrays can be converted to Python scalars

Where is this error come from? why do i have this with te second formulation
but not with the first?

A side question When i uncomment the `print(t.getshape())` i get also the
following error.

> File "C:/Users/location/test_sweep.py", line 17, in print(t.getshape())
>
> AttributeError: 'numpy.ndarray' object has no attribute 'getshape'

The first error looks like if it are multiple arrays. but the second says it
doesn have more than arrays. Why or don't i understand the error messages?


Answer: When using `numpy` arrays, you shouldn't use `math` functions. Try use `numpy`
functions:

    
    
    sine = numpy.sin(2*numpy.pi*f0*t))
    

As for the `getShape()` issue, as the error message says there is no attribute
with that name. Try:

    
    
    print(t.shape)
    

