I got a line of code from the net that works correctly, but I don't know how
import numpy as np
randomArray= np.random.uniform(1, 100, size=(5,5))
columnSumm= list(map(sum,zip(*randomArray)))
print(randomArray, columnSumm)
Please explain the third line of code in detail, in plain language.

Answer # 1

Answer # 2
You are creating an array of size
5 by 5
with random numbers from 1 to 100, then create a new array1 to 5
from the sums of each column.list
list creationFunction
map()
is used to apply a function to each element of an iterable object (such as a list or dictionary) and return a new iterator to get the resultssum
Summarizes the elements of the specified object and returns the result.function
zip
allows you to walk through several iterable objects (lists, etc.)In my case, zip goes through each line of the array?
Spenkau20220214 07:10:52yes, in this case it is passed through the columns because of the precreated list. go through the print on each step and you will understand everything, start with print(list(randomArray)) and so on
tomatomagnetregulato20220214 07:33:46
 python : correctly translate the dictionary into a dataframe, where the values will be divided by keys
 python : Error with matrix multiplication. Numpy
 python : How to avoid becoming NaN when adding pandas list elements
 Elementwise comparison of two python arrays
 python : How to access an array element
 python : How to split array elements into elements of another array? Numpy
 python : Numpy: expansion of vectormatrix product for 3D case via tensor product
 python : calculating distance between numpy vectors
 python : How to get such a slice of a numpy array
 python : Error with optimized matrix multiplication. Numpy
zip(*my_list)
is a wellknown trick in Vanilla Python to transpose a matrix (a list of lists).Example:
But since you're already using Numpy, why not take advantage of its fast and optimized methods:
for large Numpy arrays, the code will run orders of magnitude faster