Skip to content

Instantly share code, notes, and snippets.

@ppeuchin
Created November 7, 2021 21:49
Show Gist options
  • Save ppeuchin/33b690d8baa3402852e3f3e6cd6731d7 to your computer and use it in GitHub Desktop.
Save ppeuchin/33b690d8baa3402852e3f3e6cd6731d7 to your computer and use it in GitHub Desktop.
Sololearn: Data Science - Average of rows code project
import numpy as np
n, p = [int(x) for x in input().split()]
i = 0
list_arr = []
# appends empty lists(rows) for the 2d array to list_arr
# and then appends the values from each line of input into the individual lists in the list
for i in range(n):
list_arr.append([])
for x in input().split():
list_arr[i].append(float(x))
# print(list_arr)
# creates a 2d numpy array
arr_2d = np.array(list_arr)
# print(arr_2d)
# calculates the mean of the individual rows in the array
rowmeans = arr_2d.mean(axis=1)
print(rowmeans.round(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment