numpy assignment

 


1.Create a NumPy array of integers from 10 to 50. Print:
shape
data type
size
2.Create a 5×5 matrix filled with zeros, then set the border elements to your roll number.
3.Create a 4×4 identity matrix and multiply it by 5.
4.Create two random arrays of size (3,3) and: ( use np.random.randint() function)
add them
subtract them
multiply element-wise
5.Create a 1D array of numbers from 1–20.
Reshape it into:
(4,5)
(5,4)

6.Create a 6×6 matrix with numbers from 1 to 36.
Extract:
first 2 rows
last 2 columns
center 2×2 block

7.From the above matrix, extract all even numbers.
8.Replace all values greater than 20 with 0. ( use np.where)
9.Reverse a 1D array using slicing (no loops).
10.Create a matrix and swap its first and last rows.
11.Generate 50 random numbers. Find:
mean
median
standard deviation
minimum & maximum
12.Create a 5×4 random matrix.
Find:
row-wise mean
column-wise mean
13.Normalize a 1D array using:
(xmean)/std(x - mean) / std14.Find the index of:
largest value
smallest value
in a random array.
15.Generate:
    10 random integers between 1–100
    10 random floats between 0–1
16.Simulate rolling a dice 100 times.
Count how many times each number appears.
17.Create a 4×4 matrix of random integers and sort:
each row
entire matrix flattened
18.Create two 2×2 matrices and:
perform matrix multiplication
find transpose of each

19.Solve the system:

2x + y = 5 x + 3y = 6

using NumPy matrices.

20.Determinant Check
Create a 3×3 matrix with random integers (1–10).
Compute its determinant using NumPy
Check whether the matrix is singular or non-singular

21.Rank of a Matrix

Create the matrix:
[[1, 2, 3], [2, 4, 6], [1, 1, 1]]
Find its rank
Explain what the rank tells about linear dependence of rows

22.Matrix Inverse Verification

Create a random 3×3 matrix.
Compute its inverse
Multiply the matrix by its inverse
Verify that the result is approximately the identity matrix

23.Eigenvalues and Eigenvectors

For the matrix:
[[2, 0], [0, 3]]

Compute eigenvalues and eigenvectors
Verify the result using:Av=λvA v = \lambda v
24.Trace and Symmetry Test
Create a 4×4 matrix.
Compute its trace
Check whether it is symmetric (A == A.T)
If symmetric, compute its eigenvalues

25.import numpy as np

A = np.arange(1, 26).reshape(5,5)
print(A)
This creates the matrix:

[[ 1  2  3  4  5]
 [ 6  7  8  9 10]
 [11 12 13 14 15]
 [16 17 18 19 20]
 [21 22 23 24 25]]
Write the output of each of the following slicing statements:
A[1:4, 2:5]
A[:, ::2]
A[::2, ::2]
A[1:, -2:]
A[::-1, 0]

Comments

Popular posts from this blog

Programming in Python CST 362 KTU CS Sixth Semester Elective Notes

Graphical User Interfaces ( GUI)

Turtle Graphics