Numpy Exercises

| categories: Practice

Today in lab I'll answer questions and then you'll work with Numpy to hone your array hacking skills. You may do these at the command prompt or as a script. There is nothing to turn in and no grade will be assigned. Of course you may ask any questions.

  1. Construct an array containing only prime numbers greater than 100 and less than 200.
  2. Construct a 5 by 5 array containing the numbers 0 to 24 without typing the 25 values in. Your result should look like this:
     array([[ 0,  1,  2,  3,  4],
           [ 5,  6,  7,  8,  9],
           [10, 11, 12, 13, 14],
           [15, 16, 17, 18, 19],
           [20, 21, 22, 23, 24]])
        
  3. Construct a 5 by 5 array in which each cell contains the distance of that cell from the center of the array. The concept of broadcasting will be very useful here. A 3 by 3 version would look like this:
    array([[ 1.41421356,  1.        ,  1.41421356],
           [ 1.        ,  0.        ,  1.        ],
           [ 1.41421356,  1.        ,  1.41421356]])