2

I'm trying to use Numpy to create a y vector that will correspond to the following plot:

enter image description here

The x values will run from 0 to 24, the y values should be:

0 to 6 will be 0

6 to 18 will be sort of parabola

18 to 24 will be 0 again

What is a good way to do it? I don't have any practical ideas yet (I thought about some sort of interpolation).

Thank you!

1 Answer 1

1

I have done it assuming that you want a circle shape instead of a parabola (based on your scheme).

import numpy as np

length = 24
radius = 6

x = np.arange(length)
y = np.sqrt(radius**2-(x-(length/2))**2)
y = np.nan_to_num(y)

print(x)
# [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]
print(y)
# [0.         0.         0.         0.         0.         0.
#  0.         3.31662479 4.47213595 5.19615242 5.65685425 5.91607978
#  6.         5.91607978 5.65685425 5.19615242 4.47213595 3.31662479
#  0.         0.         0.         0.         0.         0.        ]
Sign up to request clarification or add additional context in comments.

3 Comments

Not exactly the thing I had in mind but it works! :)
What did you had in mind? I am just deducing y points from circle mathematical equation: (x-x_o)**2+(y-y_o)**2 = r**2. If you prefer another shape you can just modify the equation.
Yes it is working. What I had in mind is doing something more general, like part of a sine wave that will peak at the middle and zero padding everywhere else

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.