Forums

Beginner - code not getting executed for all set of values

Hi every one,

I'm completely new to Python. My manager wants me to run a python code and generate output for 40 set of values. I'm able to run the code for a set of sample values. But when I replace it with actual values, I don't get any output. Below is the code.

Sample data for which I got the output is in the code, given as data = [ ]. One set of actual data for which I would like to get output is: data = [10.7369, 10.9114, 10.2428, 10.4129, 10.6323, 10.3315, 11.213, 10.405, 10.1623, 10.4183, 10.463, 10.1772, 10.967, 10.9385, 10.4935, 10.3695, 10.708, 11.0088].

It would be a great help if anyone could help me get the output. Thanks very much.

import numpy as np
from scipy.stats import norm

def mann_kendall_test(data, alpha=0.05):
"""
Perform the Mann-Kendall test to detect trends and change points in a time series dataset.
Returns a tuple containing the test statistic, p-value, and a list of change point indices.
"""
n = len(data)
s = 0
for i in range(n-1):
    for j in range(i+1, n):
        s += np.sign(data[j] - data[i])
var_s = n*(n-1)*(2*n+5)/18
if s > 0:
    z = (s - 1) / np.sqrt(var_s)
elif s < 0:
    z = (s + 1) / np.sqrt(var_s)
else:
    z = 0
p = 2 * (1 - norm.cdf(np.abs(z)))
change_points = []
if p < alpha:
    for i in range(1, n):
        if np.sign(data[i] - data[i-1]) != np.sign(s):
            change_points.append(i-1)
return s, p, change_points

data = [10, 11, 13, 12, 15, 18, 16, 19, 20, 22, 24, 25, 27, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
s, p, change_points = mann_kendall_test(data)
print(f"Test statistic: {s}")
print(f"P-value: {p}")
print(f"Change points: {change_points}")

These are the forums for an online development environment, PythonAnywhere -- with general coding questions like that, you may be better off posting on Stack Overflow.