I'm really new to programming, and I can't figure out how to use a Numpy array to be manipulated in a function such as P**2.
import math
import numpy
span_x = numpy.array([0,250,500,750,1000])
P = span_x
example = P**2
span_y = [example for i in P]
y = float(input("Enter y: "))
bracket1 = min(span_y, lambda span_y: abs(span_y-y))
if bracket1 < y:
for i in span_y:
bracket2 = span_y[span_y.index(bracket1) + 1]
else:
for i in span_y:
bracket2 = span_y[span_y.index(bracket1) - 1]
print "Brackets: ", bracket1, bracket2
I've tried not using a Numpy array, but received a TypeError.
My main issue is that I have this array of x-values (span_x) that I want to put into a function like P**2 and get y-values (span_y) in an array. Then, the user inputs a y-value and I want to check which y-value in span_y is closest to this input, and that is bracket1. bracket2 is the second closest y-value. I would love some help!
ValueErroroccur on line:if bracket1 < y:?bracket2 = span_y[span_y.index(bracket1) - 1]Aliknotedbracket1is not an array like one those inspan_y. You need to test how you generate it.