How to get the maximum value of a single row and each column of a two-dimensional matrix in Python

php中世界最好的语言
Release: 2018-04-09 09:51:05
Original
7205 people have browsed it

This time I will bring you PythonHow to get the maximum value of each column of a single row of a two-dimensional matrix, how to get the maximum value of each column of a two-dimensional matrix in PythonWhat are the precautions, below This is a practical case, let’s take a look at it.

Because there is a small link in the project that requires this function, so I wrote a simple little function. The following is the specific implementation:

#!usr/bin/env python
#encoding:utf-8
'''
Author:沂水寒城
'''
def get_max_value(martix):
  '''
  得到矩阵中每一列最大的值
  '''
  res_list=[]
  for j in range(len(martix[0])):
    one_list=[]
    for i in range(len(martix)):
      one_list.append(int(martix[i][j]))
    res_list.append(str(max(one_list)))
  return res_list
if name == 'main':
  martix=[['1','2','3'],['3','5','0'],['5','6','2']]
  print get_max_value(martix)
Copy after login

The results are as follows:

['5', '6', '3']
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to convert a python string into a two-dimensional array

The object of diff is virtual dom

The above is the detailed content of How to get the maximum value of a single row and each column of a two-dimensional matrix in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template