Univds
Univds
b) Write a NumPy program to create a 3x3 matrix with values ranging from 2 to 10
c) Write a NumPy program to convert a list of numeric value into a one-dimensional
NumPy array
d) Write a NumPy program to convert a list and tuple into arrays
a)import numpy as np
import numpy as np
a = [1, 2, 3, 4]
print("Original array")
print(a)
x = np.asfarray(a)
print("Array converted to a float type:")
print(x)
b)import numpy as np
x = np.arange(2, 11).reshape(3,3)
print(x)
c) import numpy as np
d) import numpy as np
my_list = [1, 2, 3, 4, 5, 6, 7, 8]
print("List to array: ")
print(np.asarray(my_list))
my_tuple = ([8, 4, 6], [1, 2, 3])
print("Tuple to array: ")
print(np.asarray(my_tuple))
b) import numpy as np
x = np.sqrt([1+0j])
y = np.sqrt([0+1j])
print("Original array:x ",x)
print("Original array:y ",y)
print("Real part of the array:")
print(x.real)
print(y.real)
print("Imaginary part of the array:")
print(x.imag)
print(y.imag)
c) import numpy as np
x = np.arange(2, 11).reshape(3,3)
print(x)
d) import numpy as np
a = np.arange(4).reshape((2,2))
print("Original flattened array:")
print(a)
print("Maximum value of the above flattened array:")
print(np.amax(a))
print("Minimum value of the above flattened array:")
print(np.amin(a))
3) Write a Python Program to create data frame from array, dictionary and series of input
values
a)import pandas as pd
# Initialise data to lists.
data = [{'Geeks': 'dataframe', 'For': 'using', 'geeks': 'list'},
{'Geeks':10, 'For': 20, 'geeks': 30}]
df = pd.DataFrame.from_records(data,index=['1', '2'])
print(df)
b) import pandas as pd
df = pd.DataFrame.from_dict(data)
print(df)
4) Write a python program to compute correlation coefficient for the given data
X = [15, 18, 21, 24, 27] and Y = [25, 25, 27, 31, 32]
i=0
while i < n :
# sum of elements of array X.
sum_X = sum_X + X[i]
i=i+1
# Driver function
X = [15, 18, 21, 24, 27]
Y = [25, 25, 27, 31, 32]
5) Write a python program to Plot Linear Regression for the data x = [0, 1, 2, 3, 4, 5, 6, 7,
8, 9]
y = [1, 3, 2, 5, 7, 8, 8, 9, 10, 12]
import numpy as np
# putting labels
plt.xlabel('x')
plt.ylabel('y')
def main():
# observations / data
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
y = np.array([1, 3, 2, 5, 7, 8, 8, 9, 10, 12])
# estimating coefficients
b = estimate_coef(x, y)
print("Estimated coefficients:\nb_0 = {} \
\nb_1 = {}".format(b[0], b[1]))
if __name__ == "__main__":
main()
6) Write a Pandas program to create and display a DataFrame from a specified dictionary
data
which has the index labels.
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
import pandas as pd
import numpy as np
df = pd.DataFrame(exam_data , index=labels)
print(df)
import numpy as np
udict = """{"column0":{"a":1,"b":0.0,"c":0.0,"d":2.0},
"column1":{"a":3.0,"b":1,"c":0.0,"d":-1.0},
"column2":{"a":4,"b":1,"c":5.0,"d":-1.0},
"column3":{"a":3.0,"b":-1.0,"c":-1.0,"d":-1.0}
}"""
t = literal_eval(udict)
print("\nOriginal dictionary:")
print(t)
print("Type: ",type(t))
print("\nndarray:")
print(result_nparra)
print("Type: ",type(result_nparra))
8) Write a Pandas program to select all columns, except one given column in a
DataFrame
import pandas as pd
d = {'col1': [1, 2, 3, 4, 7], 'col2': [4, 5, 6, 9, 5], 'col3': [7, 8, 12, 1, 11]}
df = pd.DataFrame(data=d)
print("Original DataFrame")
print(df)
print("\nAll columns except 'col3':")
df = df.loc[:, df.columns != 'col3']
print(df)
9) Write a Python Program to implement and Validate Time Series Analysis in order to
predict the future value with your own sample data
10) Write a Python Program to plot a graph for the frequency Distribution of the sample
data
11)Write a NumPy program to merge three given NumPy arrays of same shape
import numpy as np
arr1 = np.random.random(size=(25, 25, 1))
arr2 = np.random.random(size=(25, 25, 1))
arr3 = np.random.random(size=(25, 25, 1))
print("Original arrays:")
print(arr1)
print(arr2)
print(arr3)
result = np.concatenate((arr1, arr2, arr3), axis=-1)
print("\nAfter concatenate:")
print(result)
12) Write a Python Program to demonstrate various styles of Plotting graph using
Matplotlib Module.
13) Write a python program to calculate the variance for variety of samples are derived
from different types of data
14) Create a normal curve using python program with your own data’s
15) Write a python program to show the result of correlation with scatter plot from your
own input’s
16)Write a Python Program to implement and Validate Linear Regression Model with
your own sample data
17) Write a Python Program to demonstrate the Z-Test and T-Test result for the sample
of 20 Students +2 exam final marks.
18) Write a Python Program to show the result of ANOVA Test for the sample of three
groups of Data
19) Write a Python Program to implement and Validate Logistic Regression Model with
your own sample data
20)