Giter VIP home page Giter VIP logo

2018_day2's Introduction

Deceivingly simple function

The file maxima.py contains a function, find_maxima, that finds local maxima in a list and returns their indices. Please read the last sentence again: it returns the indices, not the values. ;)

  1. Test the function with these input arguments and others of your own invention until you are satisfied that it does the right thing for typical cases (remember that the function returns the indices of the maxima):

    x = [0, 1, 2, 1, 2, 1, 0]
    x = [-i**2 for i in range(-3, 4)]
    x = [np.sin(2*alpha) for alpha in np.linspace(0.0, 5.0, 100)]
  2. Now try with the following inputs:

    x = [4, 2, 1, 3, 1, 2]
    x = [4, 2, 1, 3, 1, 5]
    x = [4, 2, 1, 3, 1]
  3. You may think that the code is now clean and robust... Look at the output of the function for the input list

    x = [1, 2, 2, 1]

    Does the output correspond to your intuition? Think about a reasonable default behavior in this situation, and meditate on how such a simple function can hide so many complications

  4. Implement the “reasonable behavior” you conceived in c), adding a new test. Make sure that your function handles these inputs correctly (include them in the tests):

    x = [1, 2, 2, 3, 1]
    x = [1, 3, 2, 2, 1]
    x = [3, 2, 2, 3]

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.