Note that there are some explanatory texts on larger screens.

plurals
  1. POSort on multiple NumPy arrays
    primarykey
    data
    text
    <p>I am creating a 2 dimensional numpy array that contains stock returns. I want to sum the return every 2 days, and if the sum is in the top two, I will set every element in a similar shaped array to True.</p> <p>For example, returns below is the daily returns for four different stocks.</p> <p><code> returns=np.array([<br> [0, 0, 4, 8],<br> [7, 5, 4, 1],<br> [10, 5, 7, 6],<br> [7, 5, 4, 2]]) </code></p> <p>For the first two days, columns 2 and 3 (using 0 based indexing) have the highest sums. For the second set of two days, columns 0 and 2 have the highest sums. The output array I want is</p> <p><code> bools=np.array([<br> [False, False, True, True],<br> [False, False, True, True],<br> [True, False, True, False],<br> [True, False, True, False]]) </code></p> <p>What are good ways to accomplish this?</p> <p>If there are ties with the sums of two days, I want to use another similarly shaped numpy array as tiebreakers.</p> <p>For example, if </p> <p><code> returns=np.array([<br> [0, 9, 4, 8],<br> [7, 5, 4, 0],<br> [10, 5, 7, 6],<br> [7, 5, 4, 2]]) </code></p> <p>For the first set of two days, columns 2 and 3 are tied for the second highest sum. I want to decide the tiebreaker by the greatest value in the last row for the tied columns so that the tie break between columns 2 and 3 look at tiebreaks[1][2] vs tiebreaks[1][3] (4 v 5), and that the ultimate output is bools2.</p> <p><code> tiebreaks=np.array([<br> [0, 0, 1, 1],<br> [2, 3, 4, 5],<br> [0, 5, 7, 6],<br> [-7, 5, -4, 2]]) </code></p> <p><code> bools2=np.array([<br> [False, True, False, True],<br> [False, True, False, True],<br> [True, False, True, False],<br> [True, False, True, False]]) </code></p> <p>Thanks for your help.</p>
    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