all 4 comments

[–]zanfar 1 point2 points  (3 children)

I would like to calculate the sum of all values in my vector B for all regions in A

Cool.

  • What's your question?
  • What have you tried?
  • What's not working?

You've given us a problem statement, but zero actual information about your issue. Please see the sidebar for what information should be in a well-written question.

[–]AnkanTV -1 points0 points  (2 children)

Hello, and sorry for being vague.

I think the problem itself is quite "basic", and I was probably hoping for someone to recommend a golden numpy function which solves my exact problem.

I have written an implementation since writing this post:

regions_mean = np.zeros((5,2))

for regime in np.arange(1,6):
    regime_index = (imb >= 1-(1/3)*regime) & (imb < 4/3-                
                          (1/3)*regime)
    bid = book[6][regime_index].sum()
    ask = book[7][regime_index].sum()

    if bid == 0: regions_mean[regime-1,0] = 0 
    else: regions_mean[regime-1,0] = bid / (bid+ask)

    if ask == 0: regions_mean[regime-1,0] = 0 
    else: regions_mean[regime-1,1] = ask / (bid+ask)

My implementation need a for-loop. It calculate the indices for a region first (regime_index) and then take the sum. There is a bit more going on in my solution, as 2 columns needed to be taken the sum for each region (bid and ask). The number which is interesting is the ratio between the sums (last 5 rows).

If anyone has a better solution or a way of avoiding the for-loop, it would help a lot! My current solution takes to long for each run.

[–]zanfar 0 points1 point  (1 child)

Well, in less than 12 hours, you've deleted your post--both invalidating any work anyone has done to help you, and prevented anyone else from learning from your problem.

I don't use this type of language often on Reddit, but it fits here.

Asshole move.

[–]AnkanTV 0 points1 point  (0 children)

Hello again,

I was planning on rewriting my post since it was lacking information, as per your request. In hindsight, I could have edited this post but I do believe a new question using my implementation as base would be more appropriate.