Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

matrix - Tried taking single char, printing the signs directly and diving the numbers. Wont WORK with double digits. (PYTHON 3)

Normalizing Matrices(Python)

Given N number of matrices, normalize them by diving each number in every matrix by 2.

Input Format

First line: N : Number of matrices Second line: First 4x5 matrix Similarly N+1 number of lines (including 1st line) Constraints

N >= 1 Each input matrix is always 4x5 matrix Each value in input matrix is < 150 if not print array value out of range for that particular matrix output if value in input matrix is 0 or 1, write the same number as normalized output i.e. normalized number for 0 is 0 and for 1 is 1.

Output Format

First line is output matrix of first matrix Similarly for N matrices

Sample Input 0

2 [[4, 4, 4, 4], [2, 2, 2, 2], [6, 6, 6, 6], [8, 8, 8, 8], [8, 8, 8, 8]] [[31, 91, 80, 11], [50, 11, 20, 10], [22, 33, 11, 11], [10, 12, 33, 23], [8, 8, 8, 8]]

Sample Output 0

[[2, 2, 2, 2], [1, 1, 1, 1], [3, 3, 3, 3], [4, 4, 4, 4], [4, 4, 4, 4]] [[15, 45, 40, 5], [25, 5, 10, 5], [11, 16, 5, 5], [5, 6, 16, 11], [4, 4, 4, 4]]

Explanation 0

First line is N = 2 i.e. we will be taking 2 matrices as an input Second line is the first matrix Third line is second matrix

We then divide each element in matrix with 2 [[4, 4, 4, 4], [2, 2, 2, 2], [6, 6, 6, 6], [8, 8, 8, 8], [8, 8, 8, 8]] which gives result like this [[2, 2, 2, 2], [1, 1, 1, 1], [3, 3, 3, 3], [4, 4, 4, 4], [4, 4, 4, 4]] Which we print on the first line, similarly for second matrix.

Sample Input 1

1 [[4, 4, 4, 4], [2, 2, 2, 2], [6, 6, 6, 6], [8, 8, 8, 8], [200, 8, 8, 8]]

Sample Output 1

array value out of range

Explanation 1

In 1st Matrix, array value is greater than 150, so we printed array value out of range error for that particular matrix.

question from:https://stackoverflow.com/questions/65647132/tried-taking-single-char-printing-the-signs-directly-and-diving-the-numbers-wo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...