numpy - efrc gives error length-1 array can be converted to python -
i'm trying calculate bit error rate in python numpy. code looks this:
ebbyno = arange(0,16,1) ebno = 10**(ebbyno/10) ber2 = (3/8)*erfc(cmath.sqrt(ebno*(2/5)))+(1/4)*erfc(3*sqrt(2/5*ebno))
but it's giving me error:
ber2 = (3/8)*erfc(cmath.sqrt(ebno*(2/5)))+(1/4)*erfc(3*sqrt(2/5*ebno)) typeerror: length-1 arrays can converted python scalars
cmath
not support numpy arrays:
ber2=(3/8)*erfc(sqrt(ebno*(2/5)))+(1/4)*erfc(3*sqrt(2/5*ebno))
you seem importing lot of functions from foo import *
can trip up. using ints (for example 2/5
) instead of floats equation above returns array of zero's:
>>> 2/5 0 >>> 2./5 0.4
i suggest:
>>> import numpy np >>> import scipy.special sp >>> ebbyno=np.arange(0.,16.,1) >>> ebno=10**(ebbyno/10) >>> ber2=(3./8)*sp.erfc(np.sqrt(ebno*(2./5)))+(1./4)*sp.erfc(3*np.sqrt(2./5*ebno)) >>> ber2 array([ 1.40982603e-01, 1.18997473e-01, 9.77418560e-02, 7.74530603e-02, 5.86237373e-02, 4.18927600e-02, 2.78713278e-02, 1.69667344e-02, 9.24721374e-03, 4.39033609e-03, 1.75415062e-03, 5.64706106e-04, 1.38658689e-04, 2.42337855e-05, 2.76320800e-06, 1.84185551e-07])
Comments
Post a Comment