How can I prevent the TypeError: list indices must be integers, not tuple when copying a python list to a numpy array?

The variable mean_data is a nested list, in Python accessing a nested list cannot be done by multi-dimensional slicing, i.e.: mean_data[1,2], instead one would write mean_data[1][2]. This is becausemean_data[2] is a list. Further indexing is done recursively – since mean_data[2] is a list, mean_data[2][0] is the first index of that list. Additionally, mean_data[:][0] does not … Read more

Relative imports in Python 3

It’s quite common to have a layout like this… …with a mymodule.py like this… …a myothermodule.py like this… …and a main.py like this… …which works fine when you run main.py or mypackage/mymodule.py, but fails with mypackage/myothermodule.py, due to the relative import… The way you’re supposed to run it is… …but it’s somewhat verbose, and doesn’t mix well with a shebang line like #!/usr/bin/env python3. The simplest … Read more

Curve curvature in numpy

EDIT: I put together this answer off and on over a couple of hours, so I missed your latest edits indicating that you only needed curvature. Hopefully, this answer will be helpful regardless. Other than doing some curve-fitting, our method of approximating derivatives is via finite differences. Thankfully, numpy has a gradient method that does these difference calculations for us, … Read more

SyntaxError: “can’t assign to function call”

Syntactically, this line makes no sense: You are attempting to assign a value to a function call, as the error says. What are you trying to accomplish? If you’re trying set subsequent_amount to the value of the function call, switch the order:

Python Variable Declaration

Okay, first things first. There is no such thing as “variable declaration” or “variable initialization” in Python. There is simply what we call “assignment”, but should probably just call “naming”. Assignment means “this name on the left-hand side now refers to the result of evaluating the right-hand side, regardless of what it referred to before … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)