This file contains 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
## Simple without stride and slice | |
print(y[1,2]) | |
#[Output]: | |
#9 | |
## Using ":" will go from start to end | |
## Without stride | |
print("This is without stride-:") |
This file contains 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 | |
x = np.arange(10) | |
print(x[2:5]) | |
print(x[2:5:2]) | |
#[Output]: | |
#[2 3 4] | |
#[2 4] |
This file contains 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 | |
##Let's first create 1-D array | |
x = np.arange(10) | |
print(x) | |
print(x[0]) | |
#[Output]: | |
#[0 1 2 3 4 5 6 7 8 9] | |
#0 |
This file contains 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
""""It is almost similar to the last function arange we have discussed with the parameters but the only difference is, | |
it doest not exlude the end value.""" | |
x = np.linspace(1., 4., 5) | |
print(x) | |
#[Output]: | |
#[1. 1.75 2.5 3.25 4. ] |
This file contains 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
x = np.arange(10) | |
print(x) | |
#[Output]: | |
#[0 1 2 3 4 5 6 7 8 9] | |
##It will create an array from 2 to 10(as last value is excluded) | |
y = np.arange(2, 11, dtype=np.float) | |
print(y) |
This file contains 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 | |
x = np.zeros((3, 3)) | |
print(x) | |
#[Output]: | |
#[[0. 0. 0.] | |
# [0. 0. 0.] | |
# [0. 0. 0.]] |
This file contains 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 | |
## Creating array using list | |
x = np.array([2,3,1,0]) | |
print(x) | |
#[Output]: | |
#[2 3 1 0] |
This file contains 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 | |
a = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) | |
print(a) | |
#[Output]: | |
#[[ 1 2 3] | |
# [ 4 5 6] | |
# [ 7 8 9] | |
# [10 11 12]] |
This file contains 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
## Creating a int8 type of array. | |
z = np.int8([-12,2,3]) | |
## Printing the array. | |
print(z) | |
#[Output]: | |
#array([-12, 2, 3], dtype=int8) | |
## Creating an array with datatype -> uint. |
This file contains 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
## importing numpy for creating numpy array. | |
import numpy as np | |
## Creating a normal integer array. | |
x = np.int_([1,2,4]) | |
## Printing the created array. | |
x | |
#[Output]: |