NumPy Matrix LibraryNumPy contains a matrix library, i.e. numpy.matlib which is used to configure matrices instead of ndarray objects. numpy.matlib.empty() functionThis function is used to return a new matrix with the uninitialized entries. The syntax to use this function is given below. It accepts the following parameter.
Consider the following example. ExampleOutput: [[6.90262230e-310 6.90262230e-310 6.90262304e-310] [6.90262304e-310 6.90261674e-310 6.90261552e-310] [6.90261326e-310 6.90262311e-310 3.95252517e-322]] numpy.matlib.zeros() functionThis function is used to create the matrix where the entries are initialized to zero. Consider the following example. ExampleOutput: [[0. 0. 0.] [0. 0. 0.] [0. 0. 0.] [0. 0. 0.]] numpy.matlib.ones() functionThis function returns a matrix with all the elements initialized to 1. Consider the following example. ExampleOutput: [[1. 1.] [1. 1.]] numpy.matlib.eye() functionThis function returns a matrix with the diagonal elements initialized to 1 and zero elsewhere. The syntax to use this function is given below. It accepts the following parameters.
Consider the following example. ExampleOutput: [[1 0 0] [0 1 0] [0 0 1]] numpy.matlib.identity() functionThis function is used to return an identity matrix of the given size. An identity matrix is the one with diagonal elements initializes to 1 and all other elements to zero. Consider the following example. ExampleOutput: [[1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1]] numpy.matlib.rand() functionThis function is used to generate a matrix where all the entries are initialized with random values. Consider the following example. ExampleOutput: [[0.86201511 0.86980769 0.06704884] [0.80531086 0.53814098 0.84394673] [0.85653048 0.8146121 0.35744405]] Next TopicNumPy Linear Algebra |