Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 15, 2019 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/900a39ecf356b0bf543841c56ec86d00 to your computer and use it in GitHub Desktop.
Save Robofied/900a39ecf356b0bf543841c56ec86d00 to your computer and use it in GitHub Desktop.
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