-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLeastSquare(Approach-Type2).py
80 lines (68 loc) · 1.95 KB
/
LeastSquare(Approach-Type2).py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#Using List comprehension in a single line approach
import numpy as np
print("Enter a range")
#list comprehension in one line :)
n = range(int(input()))
x = [float(input(np.array([i])))for i in n]
sum_1= sum(x) #sum function
print(x)
print(sum_1)
#User Input in Two Dimensional Array in Numpy
m = int(input("Enter Number of Rows: "))
n = int(input("Enter Number of Columns: "))
a = np.zeros((m,n),dtype=int)
u = len(a)
print('a=',a)
print('length of a i.e. u =',u)
for i in range(u):
for j in range(len(a[i])):
x = int(input("Enter an element:"))
a[i][j]=x
for i in range(u):
for j in range(len(a[i])):
print(a[i][j])
print(a)
#User input in array
import array as arr #from array import *
m = int(input("Enter the length of the array: "))
arr_1 = arr.array('i',[]) #i->integer
for i in range(m):
arr_1.append(int(input("Enter the value:")))
print(arr_1)
#Using list for two dimensional array approach
m = int(input("Enter number of Row:"))
n = int(input("Enter number of Column:"))
Mat = []
for i in range (0,m):
Mat.append([])
print("Blank columns of MAT:",Mat)
for i in range (0,m):
for j in range(0,n):
Mat[i].append(j)
Mat[i][j]=0
print("Zeroes filled in list:",Mat)
for i in range (0,m):
for j in range(0,n):
print('entry in row:', i+1,
'column:' , j+1)
Mat[i][j] = int(input())
print(Mat)
#Using list for two dimensional array approach - Type 2
m = int(input("Enter number of Row:"))
n = int(input("Enter number of Column:"))
Mat = []
for i in range (0,m):
Mat.append([])
print("Blank columns of MAT:",Mat)
for i in range (0,m):
for j in range(0,n):
Mat[i].append(j)
Mat[i][j]=0
print("Zeroes filled in list:",Mat)
u = len(Mat)
print('length of mat:',u)
for i in range(u):
for j in range(len(Mat[i])):
x = int(input("Enter an element:"))
Mat[i][j]=x
print(Mat)