Vous êtes sur la page 1sur 3

INFORMATICS PRACTICES ASSIGNMENT

Write a program to perform following operations on two (4,4)nd arrays:


A] multiplication of two arrays
B] division of all elements of second array by 7
C] rounding off all elements of both arrays to nearest integer
D] calculate co-variance, co-relation and their linear regression
>>>import numpy as np
>>>n1=eval(input(“enter the nos.:”))
>>> n2=eval(input(“enter the nos.:”))
>>>a=np.array(n1)
>>>b=np.array(n2)
>>>print(a*b)
>>>print(b/7)
>>>print(np.rint(a,b))
>>>print(“covariance of a and b is”,np.cov(a,b))
>>>print(“correlation of a and b is”,np.corrcoef(a,b))
>>>x=np.polyfit(a,b,1)
>>>print(x)
#first print statement gives output by multiplying each element of array with corresponding
element of second array
#similarly second print statement gives output by dividing all elements of second array by 7 and
so on…
# example program : enter the elements:[[1,2,3,4],[4,5,6,7],[2,4,5,5],[4,5,6,7]]
Enter the elements:[[1,2,3,4],[3,5,2,5],[2,4,5,5],[3,4,3,5]]
[[1 4 9 16]]
[12 25 12 35]]
[4 16 25 25]
[12 20 18 35]]
[[0.14285714 0.28571429 0.42857143 0.57142857]
[0.57142857 0.71428571 0.85714286 1. ]
[0.28571429 0.57142857 0.71428571 0.71428571]
[0.57142857 0.71428571 0.85714286 1. ]]
[[1.666667 0.5 1.666667 0.833333 1.666667 1.666667 1.666667 1.666667]
[0.5 2.25 0.33333 1.25 0.5 0.5 0.3333 0.5]
[1.666667 0.33333 2. 0.666667 1.666667 1.666667 2. 1.666667]
[0.833333 1.25 0.666667 0.91999997 0.833333 0.833333 0.666667 0.833333]
[1.666667 0.5 1.666667 0.833333 1.666667 1.666667 1.666667 1.666667]
[1.666667 0.5 1.666667 0.833333 1.666667 1.666667 1.666667 1.666667]
[1.666667 0.33333 2. 0.833333 0.666667 1.666667 1.666667 2. 1.666667]
[1.666667 0.5 1.666667 0.833333 1.666667 1.666667 1.666667 1.666667]
[1. 0.25819889 0.9187093 0.67419986 1. 0.91287093 1. ]
[0.25819889 1. 0.15713484 0.870388238 0.25819889 0.25819889 0.15713484
0.25819889]
[0.91287013 0.15713484 1. 0.49236596 1. 0.67419986
0.67419986 0.49236596 0.67419986]
Write a program to create a histogram using dataframe. Allow user to enter the values for the
dataframe.
>>>import numpy as np
>>>import matplotlib.pyplot as plt
>>>import pandas as pd
>>>a=eval(input(“enter the elements:”))
>>>b=np.array(a)
>>>s=pd.Dataframe(b)
>>>print(s)
>>>plt.hist([15,35,25,15,35],
bins=[0,10,20,30,40,50],
weights=[34,55,25,22,44])
Output:-Enter the elements:[[65,34],[43,53],[55,64]]
0 1
0 65 34
1 43 53
2 55 64
(array([0.,56.,25.,99.,0.]),
array([0,10,20,30,40,50]),
<a list of 5 patch objects>)

Vous aimerez peut-être aussi