NumPy Array (5)-axis of two-dimensional array

Source: Internet
Author: User

NumPy mean (), STD () and other methods are acting on the entire numpy array, if it is a two-dimensional array, but also the entire array, including all the rows and columns, but we often need it only for rows or columns, rather than the entire two-dimensional array, this time, you can define axis axis:

axis=0 represents the action on the column

axis=1 indicates the action on the line

Take the sum () sum method as an example:

Import= Np.array ([    [1, 2, 3],    [4, 5, 6],    [7, 8, 9]])     Print  a.sum ()#  print a.sum (axis=0)
# Indicates the sum of each column # [] print a.sum (Axis=1)
# Indicates the sum of each row # [6]

A comprehensive chestnut:

# Suppose there are 5 subway stations for 10 days of passenger traffic data ridership = Np.array ([    [   0,    0    ,2,    5,    0],    [ 1478, 3877, 3674, 2328, 2539],    [1613, 4088, 3991, 6461, 2691],    [1560, 3392, 3826, 47 2613],    [1608, 4802, 3932, 4477, 2705],    [1576, 3933, 3909, 4979, 2685],    [ c21/>,  229,  255,  496,  201],    [   2,    0,    1,    ,    0],    [1438, 3785, 3589, 4174, 2215],    [1342, 4043, 4009, 4665, 3033]]

The average value of the daily passenger flow is calculated from each station to find the maximum and minimum values:

def Min_and_max_riders_per_day (ridership):     = Ridership.mean (axis=0)    = Mean_ridership_per_station.max ()         = mean_ridership_per_ Station.min ()         return  (max_daily_ridership, min_daily_ridership)    Print  (Min_and_max_riders_per_day (ridership))    #  results (3239.9, 1071.2)

NumPy Array (5)-axis of two-dimensional array

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.