How Python Gets the single row per column maximum for a two-dimensional matrix

Source: Internet
Author: User
This time, we'll bring you python. How to get the maximum value of a single row per column for a two-dimensional matrix, Python to get the two-dimensional matrix of the maximum value of each column of attention to what, the following is the actual case, take a look.

Because there is a small link in the middle of the project needs this function, so write a simple small function, the following is a concrete implementation:

#!usr/bin/env python#encoding:utf-8 ' Author: Yishui Cold City ' def get_max_value (Martix): '  get the maximum value of each column in the matrix '  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_listif name = = ' main ':  martix=[[' 1 ', ' 2 ', ' 3 '],[' 3 ', ' 5 ', ' 0 '],[' 5 ', ' 6 ', ' 2 '] [  print get_max_value (Martix)

The results are as follows:

[' 5 ', ' 6 ', ' 3 ']

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How Python strings are converted to two-dimensional arrays

The object of diff is the virtual Dom

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.