0

I have 2 arrays, sample, and data. Data will hold the coordinates to an ellipse. All points inside the ellipse will be white and outside will be black.

Now I want to calculate the spatial distance between my sample array and data array (ellipse array) given a certain centre of the ellipse (x,y). All of the possible points of the centre of the ellipse are stored in another array called center_points.

However, when I run the code I receive an empty list but I expect a list of spatial distances.


import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import distance 
center_points = []

def combinations(x,y):
    dx = 2
    dy = 2
    return x-dx,y-dy

for x in range(10):
    for y in range(10):
        center_points.append(combinations(x,y))

sample = np.random.rand(100,100)

#spatial distance 
spatial_distance = []

data = np.empty((100,100))

def ellipse(x,y):
    if (x**2+y**2/3)>300: 
        return 0
    else:
        return 1

def translate(x, y, DX, DY):
    return (x- DX, y - DY)

def rotate(m, n):
    theta = np.radians(45)
    matrix = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]])
    return np.dot(matrix, (m,n))

for i in range(data.shape[0]):
     for j in range(data.shape[1]): 
          data[i][j]= ellipse(i,j)
          data[i][j]= rotate(i,j)
          for a,b in center_points: 
              data.append((translate(i,j,a,b)))
              spatial_distance.append(distance.hamming(data,sample))



1 Answer 1

0

Indentation error by the looks of things. The for loops after your rotate function will never run as they are intented such that the interpreter thinks they are part of the rotate function which returns before the loops are entered.

Although I think the line data[i][j]= rotate(i,j) in your loops will throw an error anyway.

EDIT: the original error has been edited out of the OP

2
  • Corrected the indentation error. I want the rotated coordinated to be stored in the data array. How can I do that?
    – M.Bore
    Jul 2, 2019 at 12:04
  • the output from rotate has 2 values, you cant store them both in the same place
    – DrBwts
    Jul 2, 2019 at 12:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.