|
| 1 | +# Author: OMKAR PATHAK |
| 2 | + |
| 3 | +# This program illustrates how to create an adarray from numerical ranges |
| 4 | + |
| 5 | +import numpy as np |
| 6 | + |
| 7 | +# ndarray.arange(start, stop, step, dtype) |
| 8 | +# Creates a numpy array from 1 to 20 |
| 9 | +myArray = np.arange(1, 21) |
| 10 | +print(myArray) # [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] |
| 11 | + |
| 12 | +# Specifying data type of each element |
| 13 | +myArray = np.arange(10, dtype = 'float') |
| 14 | +print(myArray) # [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] |
| 15 | + |
| 16 | +# Specifying steps to jump in between two elements |
| 17 | +myArray = np.arange(1, 21, 2) |
| 18 | +print(myArray) # [ 1 3 5 7 9 11 13 15 17 19] |
| 19 | + |
| 20 | +# ndarray.linspace(start, stop, num, endpoint, retstep, dtype) |
| 21 | +# Shows 5 equal intervals between 10 to 20 |
| 22 | +myArray = np.linspace(10, 20, 5) |
| 23 | +print(myArray) # [ 10. 12.5 15. 17.5 20. ] |
| 24 | + |
| 25 | +# if endpoint is set to false the last number inn STOP parameter is not executed |
| 26 | +myArray = np.linspace(10, 20, 5, endpoint = False) |
| 27 | +print(myArray) # [ 10. 12. 14. 16. 18.] |
| 28 | + |
| 29 | +# ndarray.lopspace returns an ndarray object that contains the numbers that are evenly spaced |
| 30 | +# on a log scale. |
| 31 | +# ndarray.logscale(start, stop, num, endpoint, base, dtype) |
| 32 | +# default base is 10 |
| 33 | +myArray = np.logspace(1.0, 3.0, num = 10) |
| 34 | +print(myArray) |
| 35 | + |
| 36 | +# [ 10. 16.68100537 27.82559402 46.41588834 77.42636827 |
| 37 | +# 129.1549665 215.443469 359.38136638 599.48425032 1000. ] |
| 38 | + |
| 39 | +myArray = np.logspace(1.0, 3.0, num = 10, base = 2) |
| 40 | +print(myArray) |
| 41 | + |
| 42 | +# [ 2. 2.33305808 2.72158 3.1748021 3.70349885 4.32023896 |
| 43 | +# 5.0396842 5.87893797 6.85795186 8. ] |
0 commit comments