Q:

Python program to create matrix using numpy

belongs to collection: Python Array Programs

0

By using numpy class we can create a matrix using two ways.

  1. Using numpy.array()
    mat = numpy.array([[10,20,30],[40,50,60],[70,70,90]])
    
  2. Using numpy.matrix()
    mat = numpy.matrix("10 20 30; 40 50 60; 70 80 90"
    

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the below program,

# Python matrix creation using numpy

# importing the numpy
import numpy as np

# creating matrix using numpy.array()
mat1 = np.array([[10,20,30],[40,50,60],[70,70,90]])
# printing matrix
print("mat1...")
print(mat1)

# creating matrix using numpy.matrix()
mat2 = np.matrix("10 20 30; 40 50 60; 70 80 90")

# printing matrix
print("mat2...")
print(mat2)

Output

mat1...
[[10 20 30]
 [40 50 60]
 [70 70 90]]
mat2...
[[10 20 30]
 [40 50 60]
 [70 80 90]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python program for matrix operations... >>
<< Python program to create matrix in Python...