Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Numpy
## returning 0's matrix
nm.zeros((2,3))
#[Output]:
#matrix([[0., 0., 0.],
# [0., 0., 0.]])
## it returns diagonal matrix i.e, 1's at diagonal and 0's elsewhere.
nm.eye(n=3, M=4, k=-1, dtype='int')
#[Output]:
#matrix([[0, 0, 0, 0],
# [1, 0, 0, 0],
# [0, 1, 0, 0]])
##4. rand()
## It return the random value
nm.rand(2)
#[Output]:
#matrix([[0.31396025, 0.05886812]])
## Multidimensional matrix
nm.rand(2,3)
#[Output]:
#matrix([[0.866112 , 0.38662401, 0.32563106],
# [0.80981318, 0.59824592, 0.85585548]])
## One can also pass the tuple for shape of the output.
nm.rand((2,3))
#[Output]:
#matrix([[0.27994566, 0.58220104, 0.76714032],
# [0.44271856, 0.69717546, 0.16341003]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.