Skip to content

Q.78 solution explained with reference #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Hemanth21k
Copy link
Contributor

Added solution with reference.
Considering your input towards the educational benefit of the answer, I am opening this PR for an explainable solution.

New solution:

  • Has a reference for the formula to calculate the distance from a point to line when given the endpoints of the line.
  • Follows the reference solution step by step, including the variables so that the formula is directly reflected in the solution.
  • Has comments explaining the output shape and what it computes regarding the step in the reference formula.
  • Also explains the equivalent of einsum operation, which computes the scalar product across the given axis.
  • Slightly faster than previous solution, the added complexity is also explained to the readers.

I hope this solution is helpful to new readers who struggle to understand the previous solution and gives a comprehensive view about applying functions and operations learned in the previous questions in the notebook.

P1 = np.random.uniform(-10,10,(10,2))
p = np.random.uniform(-10,10,( 1,2))

def distance(P0,P1,p):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename it distance_faster?

return d
print(distance(P0, P1, p))

##--------------- OR ---------------##
def distance(P0, P1, p):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename it distance_slower?

@Hemanth21k
Copy link
Contributor Author

Done. Please let me know if you want me to make more changes. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants