Typeerror: Unsupported Operand Type(s) For +: 'float' And 'list' In Python 3.6.8
I keep getting TypeError: unsupported operand type(s) for +: 'float' and 'list'. I am new to python programming and am trying to convert Matlab code into Python. Below is the tried
Solution 1:
There are multiple problems. In the expression math.cos((w[n/2 + 1 + [j]] - wc)
you are putting the integer j
in a single element list by doing [j]
. Hence [j] + any_number
does not work anymore.
Furthermore, you are indexing ar
and ter
, but these are one number (see random.uniform
). If you want an array/vector of a specific size, you can use np.random.uniform
with the size
argument.
The following should work, but uses the same random values ar
and ter
on each loop iteration:
s = np.zeros((1,n))
na = 8
ar = random.uniform(1,na)
ter = 2 * cmath.pi * random.uniform(1,na)
for i in np.arange(ntarget):
td = t - (2 * (Xc + xn[i]) / c)
pha = wcm * td + alpha * np.power(td, 2)
for j in np.arange(na):
pha = pha + ar * math.cos((w[n/2 + 1 + j] - wc) * td + ter)
print('pha :', pha)
Post a Comment for "Typeerror: Unsupported Operand Type(s) For +: 'float' And 'list' In Python 3.6.8"