Technology3 min read

numpy.matrix() Python

Abhishek Ahlawat

By Abhishek Ahlawat โ€” Recently

Founder of StudyTonight and a MERN fullstack developer. Writes about JavaScript, web development, Linux, and tech.

Summarize this article using AI

ABOUT :

numpy.matrix(data, dtype = None) : Class which returns a matrix from a string of data or array-like object. Matrix obtained is a specialised 2D array.

PARAMETERS :

  • data : data needs to be array-like or string.

  • dtype : data type of the array being returned.

RETURNS :

Interpretation of data as matrix

CODE :

# numpy.matrix class

import numpy as study

# string input
a = study.matrix('1 2 5 ; 3 4 6')
print("string input : \n", a, "\n")

# array-like input
b = study.matrix([[5, 6, 7], [4, 6, 6, 8]])
print("array-like input : \n", b)

Output :

string input : 
 [[1 2 5]
 [3 4 6]] 

array-like input : 
 [[[5, 6, 7] [4, 6, 6, 8]]]

For an query contact me at : https://www.linkedin.com/in/mohit-gupta-003512116/



Spotted something outdated or wrong?

Liked this? See more StudyTonight posts in Google results.

Add StudyTonight as a preferred source
Next questLIVE OPSStep 2 / 3

Practice real incidents in the browser

System Design Ops โ€” put out fires, ship fixes, and stack XP. Reading done. Time to play.

Play System Design
  • +XP

    Every sim

  • Incidents

    Live ops

  • Ranks

    Climb up

Read next