Good afternoon everyone, I'm trying to create an array with
numpy that contains the slope between each of the points made with the arrays
y to finally graph them with
These are the steps that I am currently following:
1. I calculate the slope for each of the points.
2. I add each calculated slope to a list.
3. The resulting list is transformed into an array of
4. Graph that array with matplotlib.
This is my code:
#!/usr/bin/python # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt x = np.array([0,1,2,3,4,5,6]) y = np.array([0,1,2,3,2,1,0]) lista =  for i in range(len(x)-1): dy = (y[i+1]-y[i]) / (x[i+1] - x[i]) lista.append(dy) pendiente = np.asarray(lista) ejex = len(x)-1 plt.plot(ejex,pendiente,'-m') plt.show()
Does anyone know a better way to do this?
Thank you very much.