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
## Working same as np.dot() | |
np.matmul([[2,3],[3,4]],[[1,2],[5,6]]) | |
#[Output]: | |
#array([[17, 22], | |
# [23, 30]]) | |
## Here matmul will automatically brodcast if dimensiona are not same | |
np.matmul([[1, 0], [0, 1]],[1,2]) |
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 libraries | |
import numpy.linalg as lnp | |
import numpy as np | |
## dot product for simple numbers. | |
np.dot(3,4) | |
#[Output]: | |
#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 new array. | |
e = np.array([21,22,23]) | |
## Creating a new array by using copy function. | |
f = e.copy() | |
## Checking the ids of both arrays | |
#3 In this case also both will have different idsIn [13]: | |
print(id(e)) |
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 new array | |
c = np.array([11,12,13]) | |
## Creating another array using view function | |
d = c.view() | |
## Checking the value of "d" | |
print(d) | |
#[Output]: |
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 library for creating numpy | |
import numpy as np | |
## Creating a 1-D array | |
a = np.array([0,2,1]) | |
print(a) | |
#[Output]: | |
#array([0, 2, 1]) |
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
## Searching | |
import numpy as np | |
## 1. argmax() | |
a = np.arange(6).reshape(2,3) | |
print(a) | |
#[Output]: | |
#[[0 1 2] |
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 | |
## 1. sort() | |
## Sorting along flattened array | |
a = np.array([[5,4],[3,1]]) | |
np.sort(a) | |
#[Output]: | |
#array([[4, 5], | |
# [1, 3]]) |
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 | |
## 1. argmax() | |
a = np.arange(6).reshape(2,3) | |
print(a) | |
#[Output]: | |
#[[0 1 2] | |
# [3 4 5]] |
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
y= a.mean(axis=1) | |
print(y) | |
#[Output]: | |
#[0.5 2.5 4.5] | |
y.reshape(3,1) | |
#[Output]: |
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.arange(6).reshape(3,2) | |
print(a) | |
#[Output]: | |
#array([[0, 1], | |
# [2, 3], | |
# [4, 5]]) |