Last active
July 17, 2019 23:23
-
-
Save GeorgeSeif/cedcdfc621ac2c55455fd256d8a71286 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| ### Create your array by directly loading in the data. You can use a list or a tuple. | |
| ### If you want to be super thorough, specify the array type | |
| np_array = np.array([[ 0, 1, 2, 3, 4], | |
| [ 5, 6, 7, 8, 9], | |
| [10, 11, 12, 13, 14]]) | |
| np_array = np.array([(1.5,2,3), (4,5,6)], dtype=float) | |
| ### Sometimes, the contents of the initial array may not be known, but we would like | |
| ### to initialise one anyways to use it later. We have a number of functions at out | |
| ### disposal here. | |
| # Creates a 3x4 array of 0's | |
| np.zeros((3,4)) | |
| # Creates a 2x3x4 array of int 1's | |
| np.ones((2,3,4), dtype=np.int16) | |
| # Creates an empty 2x3 array | |
| np.empty((2,3)) | |
| ### You can also create arrays with certain patterns like so | |
| # Creating a 1D array of numbers from 10 to 30 in increments of 5 | |
| np.arange( 10, 30, 5 ) | |
| # Creating a 1D array of numbers from 0 to 2 in increments of 0.3 | |
| np.arange( 0, 2, 0.3 ) | |
| # Creating a 1D array of 9 numbers equally spaced from 0 to 2 | |
| np.linspace( 0, 2, 9 ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment