'How can I let my function return all values of a NumPY array columnwise?

So I have this set of data:

[[ 99.14931546 104.03852715 107.43534677  97.85230675  98.74986914 
   98.80833412  96.81964892  98.56783189]
 [ 92.02628776  97.10439252  99.32066924  97.24584816  92.9267508
   92.65657752 105.7197853  101.23162942]
 [ 95.66253664  95.17750125  90.93318132 110.18889465  98.80084371
  105.95297652  98.37481387 106.54654286]
 [ 91.37294597 100.96781394 100.40118279 113.42090475 105.48508838
   91.6604946  106.1472841   95.08715803]
 [101.20862522 103.5730309  100.28690912 105.85269352  93.37126331
  108.57980357 100.79478953  94.20019732]
 [102.80387079  98.29687616  93.24376389  97.24130034  89.03452725
   96.2832753  104.60344836 101.13442416]
 [106.71751618 102.97585605  98.45723272 100.72418901 106.39798503
   95.46493436  94.35373179 106.83273763]
 [ 96.02548256 102.82360856 106.47551845 101.34745901 102.45651798
   98.74767493  97.57544275  92.5748759 ]
 [105.30350449  92.87730812 103.19258339 104.40518318 101.29326772
  100.85447132 101.2226037  106.03868807]
 [110.44484313  93.87155456 101.5363647   97.65393524  92.75048583
  101.72074646  96.96851209 103.29147111]
 [101.3514185  100.37372248 106.6471081  100.61742813 105.0320535
   99.35999981  98.87007532  95.85284217]
 [ 97.21315663 107.02874163 102.17642112  96.74630281  95.93799169
  102.62384733 105.07475277  97.59572169]
 [ 95.65982034 107.22482426 107.19119932 102.93039474  85.98839623
   95.19184343  91.32093303 102.35313953]
 [100.39303522  92.0108226   97.75887636  93.18884302 100.44940274
  108.09423367  96.50342927  99.58664719]
 [103.1521596  109.40523174  93.83969256  99.95827854 101.83462816
   99.69982772 103.05289628 103.93383957]
 [106.11454989  88.80221141  94.5081787   94.59300658 101.08830521
   96.34622848  96.89244283  98.07122664]
 [ 96.78266211  99.84251605 104.03478031 106.57052697 105.13668343
  105.37011896  99.07551254 104.15899829]
 [101.86186193 103.61720152  99.57859892  99.4889538  103.05541444
   98.65912661  98.72774132 104.70526438]
 [ 97.49594839  96.59385486 104.63817694 102.55198606 105.86078488
   96.5937781   93.04610867  99.92159953]
 [ 96.76814836  91.6779221  101.79132774 101.20773355  98.29243952
  101.83845792  97.94046856 102.20618501]
 [106.89005002 106.57364584 102.26648279 107.40064604  99.94318168
  103.40412146 106.38276709  98.00253006]
 [ 99.80873105 101.63973121 106.46476468 110.43976681 100.69156231
   99.99579473 101.32113654  94.76253572]
 [ 96.10020311  94.57421727 100.80409326 105.02389857  98.61325194
   95.62359311  97.99762409 103.83852459]
 [ 94.11176915  99.62387832 104.51786419  97.62787811  93.97853495
   98.75108352 106.05042487 100.07721494]]

and now I want to print my data out columnwise using NumPY, so if the dataset above is the data, I expect to get this output back:

[99.14931546, 92.02628776, 95.66253664, 91.37294597, 101.20862522, 102.80387079, 106.71751618, 96.02548256, 105.30350449, 110.44484313, 101.3514185, 97.21315663, 95.65982034, 100.39303522, 103.1521596, 106.11454989, 96.78266211, 101.86186193, 97.49594839, 96.76814836, 106.89005002, 99.80873105, 96.10020311, 94.11176915]
[104.03852715, 97.10439252, 95.17750125, 100.96781394, 103.5730309, 98.29687616, 102.97585605, 102.82360856, 92.87730812, 93.87155456, 100.37372248, 107.02874163, 107.22482426, 92.0108226, 109.40523174, 88.80221141, 99.84251605, 103.61720152, 96.59385486, 91.6779221, 106.57364584, 101.63973121, 94.57421727, 99.62387832]
[107.43534677, 99.32066924, 90.93318132, 100.40118279, 100.28690912, 93.24376389, 98.45723272, 106.47551845, 103.19258339, 101.5363647, 106.6471081, 102.17642112, 107.19119932, 97.75887636, 93.83969256, 94.5081787, 104.03478031, 99.57859892, 104.63817694, 101.79132774, 102.26648279, 106.46476468, 100.80409326, 104.51786419]
[97.85230675, 97.24584816, 110.18889465, 113.42090475, 105.85269352, 97.24130034, 100.72418901, 101.34745901, 104.40518318, 97.65393524, 100.61742813, 96.74630281, 102.93039474, 93.18884302, 99.95827854, 94.59300658, 106.57052697, 99.4889538, 102.55198606, 101.20773355, 107.40064604, 110.43976681, 105.02389857, 97.62787811]
[98.74986914, 92.9267508, 98.80084371, 105.48508838, 93.37126331, 89.03452725, 106.39798503, 102.45651798, 101.29326772, 92.75048583, 105.0320535, 95.93799169, 85.98839623, 100.44940274, 101.83462816, 101.08830521, 105.13668343, 103.05541444, 105.86078488, 98.29243952, 99.94318168, 100.69156231, 98.61325194, 93.97853495]
[98.80833412, 92.65657752, 105.95297652, 91.6604946, 108.57980357, 96.2832753, 95.46493436, 98.74767493, 100.85447132, 101.72074646, 99.35999981, 102.62384733, 95.19184343, 108.09423367, 99.69982772, 96.34622848, 105.37011896, 98.65912661, 96.5937781, 101.83845792, 103.40412146, 99.99579473, 95.62359311, 98.75108352]
[96.81964892, 105.7197853, 98.37481387, 106.1472841, 100.79478953, 104.60344836, 94.35373179, 97.57544275, 101.2226037, 96.96851209, 98.87007532, 105.07475277, 91.32093303, 96.50342927, 103.05289628, 96.89244283, 99.07551254, 98.72774132, 93.04610867, 97.94046856, 106.38276709, 101.32113654, 97.99762409, 106.05042487]
[98.56783189, 101.23162942, 106.54654286, 95.08715803, 94.20019732, 101.13442416, 106.83273763, 92.5748759, 106.03868807, 103.29147111, 95.85284217, 97.59572169, 102.35313953, 99.58664719, 103.93383957, 98.07122664, 104.15899829, 104.70526438, 99.92159953, 102.20618501, 98.00253006, 94.76253572, 103.83852459, 100.07721494]

This is what I have so far, which doesn't work at all.

import numpy as np
data = np.genfromtxt('./data/normal_distribution.csv', delimiter=",")  
j = len(data[0])
q = []
for x in data:
    for w in range(0,j):
        q.append(x[w])
print(q)

What changes should I make to correct my code?



Solution 1:[1]

Example for the first 2 samples (accordingly to @enke):

arr = np.array([[ 99.14931546, 104.03852715, 107.43534677,  97.85230675,  98.74986914, 
   98.80833412,  96.81964892,  98.56783189],
 [ 92.02628776,  97.10439252,  99.32066924,  97.24584816,  92.9267508,
   92.65657752, 105.7197853,  101.23162942]])

# tranpose array
print(arr.T)

[[ 99.14931546  92.02628776]
 [104.03852715  97.10439252]
 [107.43534677  99.32066924]
 [ 97.85230675  97.24584816]
 [ 98.74986914  92.9267508 ]
 [ 98.80833412  92.65657752]
 [ 96.81964892 105.7197853 ]
 [ 98.56783189 101.23162942]]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JAdel