0

I am getting "SyntaxError: can't assign to function call" for a code on DWT on a signal from a text file. I appreciate if anyone can explain why is this syntax error.

import numpy as np
import pywt
import array
array.array('i')
k = array.array('i',(0 for i in range(1,9))) #x = [0 for i in xrange()]
for x in k:
filename = ('F00%d.txt', x)
file = open(filename, mode + 'r')
text = file.read()
file.close()
cA1, cD1 = pywt.dwt(text,'db4')
cA2, cD2 = pywt.dwt(cD1,'db4')
cA3, cD3 = pywt.dwt(cD2,'db4')
cA4, cD4 = pywt.dwt(cD3,'db4')
cA5, cD5 = pywt.dwt(cD4,'db4')

m(k, 1) = np.mean(cD5) 
s(k, 1) = np.std(cD5)
ma(k, 1) = max(cD5)
mi(k, 1) = min(cD5)

There are 9 files in a folder which I am reading one by one (columnise) and applying DWT and then computing some statistical parameters. Thank you in advance.

Dattaprasad
  • 105
  • 2
  • 12
  • If you are getting an error, it would be helpful if you posted the entire stack trace. – juanpa.arrivillaga Mar 06 '17 at 07:19
  • 1
    I'm guessing it's this line, thought: `m(k, 1) = np.mean(cD5) `... what do you expect that to do? In any even, the error seems to be pretty clear: you can't assign to a function call. – juanpa.arrivillaga Mar 06 '17 at 07:20
  • 1
    I guess you're coming from `matlab` where `()` is both -- function call and array manipultations, in `python` `()` is only function call and you obviously can't assign to it. Maybe you were intending to do `m[k, 1] = mp.mean(cD5)`? – Darth Kotik Mar 06 '17 at 07:34
  • Your for loop is not formatted correctly, its not indented. Where does it end , after the file.close? – death and gravity Mar 06 '17 at 07:45
  • Yes Darth Kotil, I have written first MATLAB code and then did conversion to Python. So, I need to check this line. – Dattaprasad Mar 06 '17 at 08:01
  • Juanpa.arrivillage, you are right. Its the line m(k, 1) = np.mean(cD5) which is resulting in error. Thank you for the valuable input. – Dattaprasad Mar 06 '17 at 08:04

0 Answers0