Giter Site home page Giter Site logo

heineman / python-algorithms Goto Github PK

View Code? Open in Web Editor NEW
195.0 195.0 99.0 2.14 MB

This repository contains the code associated with the "Working With Algorithms In Python" Safari Video. http://shop.oreilly.com/product/110000667.do

Python 100.00%

python-algorithms's People

Contributors

heineman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-algorithms's Issues

KDNode and nearest

I'm watching your video on Safari. I read your README regarding the KDNode and nearest. Would you give an example of points where lines 99 to 118 is necessary? I tried the following as a test between your code and the revised version of nearest below. Both gave the same output.

kd = KDTree()
kd.add([2,3])
kd.add([3,4])
kd.add([5,5])
kd.add([9,6])
kd.add([4,7])
kd.add([8,1])
kd.add([7,2])
v = kd.nearest((4,4))
print(v.point)

And simplify the function to

  def nearest(self, min_distance, p):
        """Return closest node from given subtree to point."""

        d = self.distance(p)
        result = None
        if (d < min_distance):
            result = self
            min_distance = d

        pt = None
        if self.isAbove(p) and self.above:
            pt = self.above.nearest(min_distance, p)
        elif self.isBelow(p) and self.below:
            pt = self.below.nearest(min_distance, p)
        if pt:
            return pt

        return result

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.