Skip to content

Instantly share code, notes, and snippets.

## 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])
##importing libraries
import numpy.linalg as lnp
import numpy as np
## dot product for simple numbers.
np.dot(3,4)
#[Output]:
#12
## 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))
## 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]:
## 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])
## Searching
import numpy as np
## 1. argmax()
a = np.arange(6).reshape(2,3)
print(a)
#[Output]:
#[[0 1 2]
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]])
import numpy as np
## 1. argmax()
a = np.arange(6).reshape(2,3)
print(a)
#[Output]:
#[[0 1 2]
# [3 4 5]]
y= a.mean(axis=1)
print(y)
#[Output]:
#[0.5 2.5 4.5]
y.reshape(3,1)
#[Output]:
import numpy as np
a = np.arange(6).reshape(3,2)
print(a)
#[Output]:
#array([[0, 1],
# [2, 3],
# [4, 5]])