#!============================================================================ #! NumPy #!============================================================================ import numpy #! 1. Construct an array from the list: [1,2,3] print '================================================' print '#! 1. Construct an array from the list: [1,2,3]' print '================================================' #! 2. Cast it into floats print '\n================================================' print '#! 2. Cast it into floats' print '================================================' #! 3. Create an array of int ranging from 0-10 print '\n================================================' print '#! 3. Create an array of int ranging from 0-10' print '================================================' #! 4. Create an array containing 7 evenly spaced numbers between 0 and 23 print '\n================================================' print '#! 4. Create an array containing 7 evenly spaced numbers between 0 and 23' print '================================================' #! 5. Create an array with shape (2,5,5,2) containing only the number 5 print '\n================================================' print '#! 5. Create an array with shape (2,5,5,2) containing only the number 5' print '================================================' #! 6. Reshape the resulting array from shape (2,5,5,2) to only 2D print '\n================================================' print '#! 6. Reshape the resulting array from shape (2,5,5,2) to only 2D' print '================================================' #! 7. Starting from a=numpy.arange(10) and b=numpy.arange(5) # create the array [0,1,2,3,4,4,3,2,1,0] print '\n================================================' print '#! 7. Starting from a=numpy.arange(10) and b=numpy.arange(5) # create the array [0,1,2,3,4,4,3,2,1,0]' print '================================================' #! 8. Calculate the mean, std, var, max, min, of an array with shape (15,15) containing floats drawn from a normal #distribution with mean 21 and sigma 4.5 (use numpy.random.normal()) print '\n================================================' print '#! 8. Calculate the mean, std, var, max, min, of an array with shape (15,15) containing floats drawn from a normal distribution with mean ' print '================================================' #! 9. Do the same but not on all elements but only on the 1nd dimension print '================================================' print '#! 9. Do the same but not on all elements but only on the 1nd dimension' print '================================================' #! 10. Transform the array such that it is only 1d print '\n================================================' print '#! 10. Transform the array such that it is only 1d' print '================================================' #! 11. Remove all values smaller 15 and larger 26 print '\n================================================' print '#! 11. Remove all values smaller 15 and larger 26' print '================================================' #! 12. Clip all values smaller 15 and larger 26 to NaN (hint:clip ) print '\n================================================' print '#! 12. Clip all values smaller 15 and larger 26 to NaN (hint:clip )' print '================================================' #! 13. Calculate the sum of the resulting array. It should not be NaN! (hint:nansum) print '\n================================================' print '#! 13. Calculate the sum of the resulting array. It should not be NaN! (hint:nansum)' print '================================================' #! 14. Convert the NaN's to 0.0 (hint: nan_to_sum) print '\n================================================' print '#! 14. Convert the NaN\'s to 0.0 (hint: nan_to_sum)' print '================================================' #! 15. Save the array and load it again print '\n================================================' print '#! 15. Save the array and load it again' print '================================================'