Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 views4 pages

DRA Lab Exp6

The document outlines an experiment using the NumPy module in Python to create various matrix models, including a matrix from a CSV file, zero matrix, ones matrix, identity matrix, and random matrix. It provides source code for each step and describes the dataset as a 3x3 grid of numerical values. The experiment concludes with a successful execution of the matrix models using the provided dataset.

Uploaded by

bborigarla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

DRA Lab Exp6

The document outlines an experiment using the NumPy module in Python to create various matrix models, including a matrix from a CSV file, zero matrix, ones matrix, identity matrix, and random matrix. It provides source code for each step and describes the dataset as a 3x3 grid of numerical values. The experiment concludes with a successful execution of the matrix models using the provided dataset.

Uploaded by

bborigarla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DATE:

EXPRIMENT-6
NUMPY MODULE FOR MATRIX MODELS
AIM: To develop python program for matrix models by using numpy module.

SOURCE CODE:

import numpy as np

# Step 1: Create a 2D array (matrix) from a list

matrix_from_list = np.loadtxt('matrix_data.csv', delimiter=',')

print("Matrix from List:")

print(matrix_from_list)

# Step 2: Create a zero matrix (3x3)

zero_matrix = np.zeros((3, 3))

print("\nZero Matrix (3x3):")

print(zero_matrix)

# Step 3: Create a ones matrix (2x4)

ones_matrix = np.ones((2, 4))

print("\nOnes Matrix (2x4):")

print(ones_matrix)

# Step 4: Create an identity matrix (4x4)

identity_matrix = np.eye(4)

print("\nIdentity Matrix (4x4):")

print(identity_matrix)

# Step 5: Create a random matrix (3x3)

random_matrix = np.random.rand(3, 3)
print("\nRandom Matrix (3x3):")

print(random_matrix)

DATASET DESCRIPTION:

The matrix data represents a simple 3x3 grid of numerical values saved in a CSV file format. Each row in
the matrix corresponds to a set of values separated by commas, allowing for easy loading and
manipulation using Python’s NumPy library.

 Rows: Each row represents a separate list of values.


 Columns: Each column represents an individual element within the rows.
 Shape: This matrix is a 3x3 square matrix with three rows and three columns.

This matrix can be used in various computational applications, such as linear algebra operations,
transformations, or for educational purposes in understanding matrix data structures.

Data give below:

1 2 3

4 5 6

7 8 9

. Save data set by ‘matrix_data.csv’.

OUTPUT:
Matrix from List:
[[1 2 3]
[4 5 6]
[7 8 9]]

Zero Matrix (3x3):


[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
Ones Matrix (2x4):
[[1. 1. 1. 1.]
[1. 1. 1. 1.]]

Identity Matrix (4x4):


[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
Random Matrix (3x3):
[[0.83489341 0.81429439 0.89072867]
[0.19209183 0.14419781 0.68256356]
[0.12222279 0.09337582 0.27508651]]

RESULT:
Numpy module for matrix models by using number data set is successfully executed.

You might also like