Is there a one line code to find maximal value in a matrix?

前端 未结 4 1420
囚心锁ツ
囚心锁ツ 2021-01-08 01:27

To find the maximal value in a matrix of numbers, we can code 5 lines to solve the problem:

ans = matrix[0][0]
for x in range(len(matrix)):
    for y in rang         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-08 02:00

    You can also flatten your array:

    from itertools import chain
    
    flatten = chain.from_iterable
    
    max(flatten(matrix))
    

提交回复
热议问题