0% found this document useful (0 votes)
12 views2 pages

Akhilesh Verma - Program3

Programming

Uploaded by

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

Akhilesh Verma - Program3

Programming

Uploaded by

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

Program no.

Creating Numpy array:

import numpy as np
#creating 1 d array
arr=np.array([1,2,3])
print(arr)
Basic Statistical Operations:

# setup a random 2 x 4 matrix


arr = 10*np.array([[2,5],[3,4]])
print(arr)
# compute the mean for all elements
print(arr.mean())

# sum all the elements

arr = 10*np.array([[2,5],[3,4]])
print(arr)
print()
print(arr.sum())
print(arr.sum(axis=0))
print(arr.sum(axis=1))

3. Write a program to input and print the element sum of user


defined matrix
Solution: import numpy as np

print("Enter dimensions of matrix as m x n")

m = int(input("Enter the number of rows: "))

n = int(input("Enter the number of columns: "))

mat = []

for i in range(n):
Program no.3
print("Enter the",str(i+1)+"st", "row of the matrix, elements seperated by spaces")

temp = list(map(int, input().split()))

mat.append(temp)

mat = np.array(mat)

print("sum of elements of the matrix is: ", mat.sum())

You might also like