Perform function on multiple columns in python
Question: I have a data array of 30 trials(columns) each of 256 data points (rows) and
would like to run a wavelet transform (which requires a 1D array) on each
column with the eventual aim of obtaining the mean coefficients of the 30
trials. Can someone point me in the right direction please?


Answer: If you have a multidimensional numpy array then you can use a for loop:

    
    
    import numpy as np
    
    A = np.array([[1,2,3], [4,5,6]])
    
    # A is the matrix:  1 2 3
    #                   4 5 6
    
    for col in A.transpose():
        print("Column:", col)
        # Perform your wavelet transform here, you can save the
        # results to another multidimensional array.
    

This gives you access to each column as a 1D array.

Output:

    
    
    Column:  [1 4]
    Column:  [2 5]
    Column:  [3 6]
    

If you want to access the rows rather than the columns then loop through `A`
rather than `A.transpose()`.

