Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I average an array of arrays in python?
    primarykey
    data
    text
    <p>I have a simulation that runs over many times. Each time an array is produced and I insert it into a larger array keeping track of all the data. for example </p> <pre><code>record = [] for i in range(2): r = random.random() array = numpy.arange(20)*r array.shape = (10,2) record.append(array) record = numpy.array(record) </code></pre> <p>which produces:</p> <pre><code>[[[ 0. 0.88765927] [ 1.77531855 2.66297782] [ 3.55063709 4.43829637] [ 5.32595564 6.21361492] [ 7.10127419 7.98893346] [ 8.87659274 9.76425201] [ 10.65191128 11.53957056] [ 12.42722983 13.3148891 ] [ 14.20254838 15.09020765] [ 15.97786693 16.8655262 ]] [[ 0. 0.31394919] [ 0.62789839 0.94184758] [ 1.25579677 1.56974596] [ 1.88369516 2.19764435] [ 2.51159354 2.82554274] [ 3.13949193 3.45344112] [ 3.76739031 4.08133951] [ 4.3952887 4.70923789] [ 5.02318709 5.33713628] [ 5.65108547 5.96503466]]] </code></pre> <p>Since each <code>array</code> represents a simulation in my program. I would like to average the 2 different arrays contained within <code>record</code>. </p> <p>basically I would like an array with the same dimensions as <code>array</code> but it would be an average of all the individual runs. </p> <p>I could obviously just loop over the arrays but there is a lot of data in my actual simulations so I think it would be very costly on time </p> <p>example out put (obviously it wouldn't be zero):</p> <pre><code>average = [[0.0, 0.0] [0.0, 0.0] [0.0, 0.0] [0.0, 0.0] [0.0, 0.0] [0.0, 0.0] [0.0, 0.0] [0.0, 0.0] [0.0, 0.0] [0.0, 0.0]] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload