numpy.matrix() in Python

The Python numpy.matrix() function returns a matrix from the string of data of array-like object. The returned matrix is a specialized 2D array.

Basic Syntax

Following is the basic syntax for numpy.matrix() function in Python:

numpy.matrix(data, dtype = None)

And the parameters are:

ParameterDescription
dataData needs to be array-like or String.
dtypeReturned type data type.

Return Value

This function returns 2D specialized array from a string of data or array-like object.

Example

Following are the examples:

Example 1

The output for the above program is as given below:

String like input :
[[1, 2],
[3, 4],
[5, 6]]
Array like input :
[[[1, 2, 3],
[7, 8]]]

Example 2

The output for the above program is as given below:

Array like input :
[[[10, 20, 30, 40],
[50, 60, 70, 80]]]

LEAVE A REPLY

Please enter your comment!
Please enter your name here