Python stats.linregress syntax error

1.2k Views Asked by At

I am trying to calculate the regression of the x and y variables, trace_no and twwt, respectively.

The variable are 151 x 1 arrays.

The code is outputting a syntax error:

File "./seabed_dip_correction.py", line 32
    slope, intercept, r_value, p_value, std_err, Syy/Sxx = stats.linregress(trace_no,twtt)
SyntaxError: can't assign to operator

I have tried switching the operator around i.e. stats.linregress() = ...but that doesn't work.

Here is my code, could someone please tell me where I am going wrong?

data=np.genfromtxt('trace1_offset_gather.dat')
trace_no=data[:,[0]]
twtt=data[:,[1]]

slope, intercept, r_value, p_value, std_err, Syy/Sxx = stats.linregress(trace_no,twtt)
1

There are 1 best solutions below

5
On

Your last variable, or rather pair of variables, is invalid.

Syy/Sxx

If that is supposed to be a single variable, know that you cannot have / in your variable name.

Python identifiers and keywords

Identifiers (also referred to as names) are described by the following lexical definitions:

identifier ::=  (letter|"_") (letter | digit | "_")*
letter     ::=  lowercase | uppercase
lowercase  ::=  "a"..."z"
uppercase  ::=  "A"..."Z"
digit      ::=  "0"..."9"

Identifiers are unlimited in length. Case is significant.

If that is meant to be two variables, you cannot assign a value to an expression like this, it would be like saying

a/b = 2

That makes sense in mathematics, but not in Python, you must assign a value to a single variable, or in the case of unpacking N values to N variables.

Edit
The function scipy.stats.linregress only returns 5 values, and they are

slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)