To take the mean of different columns for a given row in Python, you can use the numpy
library. Here's an example of how you can do it:
main.py370 chars16 lines
In this example, we have a 2D array data
representing a table with rows and columns. We specify the row_index
variable to indicate which row we want to calculate the mean for. Then, np.mean
calculates the mean of the specified row using axis=1
, which means we want to calculate the mean across columns.
Note that np.mean
returns a single value or an array of mean values if you have multiple rows. In this case, since we only have one row, mean_values
will contain the mean value(s) for the specified row.
gistlibby LogSnag