Given two matrices, please return the multiplication result of these two matrices.
Following is an example input:
2 3 1 2 3 4 5 6
3 2 7 8 9 10 11 12
The answer should be
2
2
58
64
139
154
The first two numbers represent the row and column of the input matrix, and the rest are values in row-major order.
(You cannot use numpy, scipy, or any other python numeric library to solve the matrix multiplication.)
Please use the main function directly and implement the function Matrix_Mul.
def Matrix_Mul(mat_A, mat_B):
implement here..
def main():
X_info = list(map(int,input().split(" ")))
X = np.array(X_info[2:]).reshape((X_info[0], X_info[1]))
Y_info = list(map(int,input().split(" ")))
Y = np.array(Y_info[2:]).reshape((Y_info[0], Y_info[1]))
result = Matrix_Mul(X, Y)
print(f"{result.shape[0]}\n{result.shape[1]}")
for i in range(result.shape[0]):
for j in range(result.shape[1]):
print(int(result[i,j]))
if __name__ == "__main__":
main()
締切: 01/23 23:59
Given a 2x2 matrix A and a 2x1 vector b, please solve the equation Ax=b.
The step of achieving this is
1. compute the inversion of A
2. multiply the inverted A to b
Following is an example input
1 2 3 4
1 1
The matrix values are in row-major order.
Following are example out: (please print the results to 2nd decimal place)
-1.00
1.00
(You cannot use numpy, scipy, or any other python numeric library to solve the matrix inversion and matrix multiplication.
Hint: you can use the matrix multiplication you wrote in PY6.)
Please use the main function directly and implement the function solve_x.
def solve_x(A, b):
implement here..
def main():
A_info = list(map(int,input().split(" ")))
A = np.array(A_info).reshape((2,2))
## b -> no need to put size in front of values.
b_info = list(map(int,input().split(" ")))
b = np.array(b_info)
x = solve_x(A, b)
if x is None:
print('(can not solve.)')
else:
for i in range(x.shape[0]):
print(f'{x[i]:.2f}')
if __name__ == "__main__":
main()
締切: 01/23 23:59
Given a 3x3 matrix, please return the inverted matrix.
P.S. Before you submit your code, please check whether you can obtain a matrix that is numerically close to the identity matrix if you compute the dot product betweenthe input matrix and the inverted matrix.
Following are example output when invert an identity matrix:
1
0
0
0
1
0
0
0
1
(You cannot use numpy, scipy, or any other python numeric library)
Please use the main function directly and implement the function Inv_x.
def Inv_x(mat):
implement here..
def main():
x_info = list(map(int,input().split(" ")))
x = np.array(x_info).reshape(3,3)
result = Inv_x(x)
for i in range(result.shape[0]):
for j in range(result.shape[1]):
print(f"{result[i,j]:.3f}")
if __name__ == "__main__":
main()
締切: 01/23 23:59
Given a set of 2D points, please find the best-fitted straight line represented as y=mx+b.
Following are example input:
3
1.0 2.0
3.0 4.0
5.0 6.0
Please print the results: m and b (to 2nd decimal place)
(You cannot use numpy, scipy, or any other python numeric library)
Please use the main function directly and implement the function Inv_x_3.
def lsq_line_solution(all_points):
implement here..
def main():
point_count = int(input())
all_coords = []
for i in range(point_count):
coords = list(map(float,input().split(" ")))
all_coords.append(coords)
all_coords = np.array(all_coords)
lsq_m, lsq_b = lsq_line_solution(all_coords)
lsq_m = round(lsq_m, 2)
lsq_b = round(lsq_b, 2)
print(f'{lsq_m:.2f}')
print(f'{lsq_b:.2f}')
if __name__ == "__main__":
main()
締切: 01/23 23:59
Given a set of 2D points, please find the least-square best-fitted circle.
Following are example input:
3
1.0 2.0
3.0 4.0
5.0 6.0
Please print the parameters of the resulted circle: xc, yc and r (to 2nd decimal place).
(You cannot use numpy, scipy, or any other python numeric library)
Please use the main function directly and implement the function Inv_x_3.
def least_square_circle(all_points):
implement here..
def main():
point_count = int(input())
all_coords = []
for i in range(point_count):
coords = list(map(float,input().split(" ")))
all_coords.append(coords)
all_coords = np.array(all_coords)
cx, cy, r = least_square_circle(all_coords)
print(f'{cx:.2f}')
print(f'{cy:.2f}')
print(f'{r:.2f}')
if __name__ == "__main__":
main()
締切: 01/23 23:59