0

# How do i go about seperating my numerical data into fuzzy sections and putting it into code in Python ?

My inputs X1 and X2 are the values from -12 and 12 including 0 (i.e:(-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12) for both X1 and X2 and my output y is the function y=(2*(X1^2))+(X2^2),. In my code I got the values for y as [432 363 300 243 192 147 108 75 48 27 12 3 0 3 12 27 48 75 108 147 192 243 300 363 432]

### 1 Answer by Expert Tutors

5.0 5.0 (9 lesson ratings) (9)
0
for loops and dictionaries are your best friends in the world

#declare y as a dictionary to allow for negative indexing
y = {}

#calculate all y
for x1 in range(-12,13):
#add a new dictionary to the main dictionary at the key of x1's current value to allow multidimensional space
y[x1] = {}
for x2 in range(-12,13):
y[x1][x2] = 2*x1*x1 + x2*x2

#print all y (could be done in line with calculation for efficiency but done separately for understanding
for x1 in range(-12, 13):
for x2 in range(-12,13):
print "y[%d][%d] = %d" %(x1, x2, y[x1][x2])