Answer the question
In order to leave comments, you need to log in
How to find the values of derivatives of a created numpy array in python?
Hello!
Now I'm learning and I have the following task:
Create an array of 20 random values using the Numpy method. Find the values of the derivatives for the created array
Found a solution to this problem on the Internet:
import numpy as np
m=np.random.uniform(1, 10, 20)
dx = np.random.random()
n=np.diff(m)/dx
print(dx)
print(n)
Please tell me why such a solution? Why is .uniform used when creating the array m and not .rand, or is this not a critical difference? and another question why do we create dx and divide np.diff(m) by it? What does "Find the values of derivatives for the created array" mean?
Answer the question
In order to leave comments, you need to log in
What is the derivative of a function, you know?
Well, imagine that an array is a set of function values at successive points.
True, the question remains, which step to take - i.e., how far along the X axis are the zero element and the first element separated from each other. The simplest case - we consider the index of the element in the array as the X coordinate. But then the derivative is generally considered trivial, since the distance along X between neighboring points will be equal to 1. In the example you gave, the step (dx) is chosen randomly.
The example code shows the simplest way to calculate the derivative with respect to two points. It is simple, though sensitive to errors. There are others.
uniform generates real numbers like 1.23 etc, while randint only generates integers
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question