Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:26:38+00:00 2026-06-04T09:26:38+00:00

I need to calculate some direction arrays in numpy. I divided 360 degrees into

  • 0

I need to calculate some direction arrays in numpy. I divided 360 degrees into 16 groups, each group covers 22.5 degrees. I want the 0 degree in the middle of a group, i.e., get directions between -11.25 degrees and 11.25 degrees. But the problem is how can I get the group between 168.75 degrees and -168.75 degrees?

a[numpy.where(a<0)] = a[numpy.where(a<0)]+360
for m in range (0,3600,225):
        b = (a*10 > m)-(a*10 >= m+225).astype(float)    
        c = numpy.apply_over_axes(numpy.sum,b,0)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:26:41+00:00Added an answer on June 4, 2026 at 9:26 am

    If you want to divide data into 16 groups, having 0 degree in the middle, why are you writing for m in range (0,3600,225)?

    >>> [x/10. for x in range(0,3600,225)]
    [0.0, 22.5, 45.0, 67.5, 90.0, 112.5, 135.0, 157.5, 180.0, 202.5, 225.0, 247.5,
     270.0, 292.5, 315.0, 337.5]
    ## this sectors are not the ones you want!
    

    I would say you should start with for m in range (-1125,36000,2250) (note that now I am using a 100 factor instead of 10), that would give you the groups you want…

    wind_sectors = [x/100.0 for x in range(-1125,36000,2250)]
    for m in wind_sectors:
        #DO THINGS
    

    I have to say I don’t really understand your script and the goal of it…
    To deal with circle degrees, I would suggest something like:

    • a condition, where you put your problematic data, i.e., the one where you have to deal with the transition around zero;
    • a condition where you put all the other data.

    For example, in this case, I am printing all the elements from my array that belong to each sector:

    import numpy
    
    def wind_sectors(a_array, nsect = 16):
        step = 360./nsect
        init = step/2
        sectores = [x/100.0 for x in range(int(init*100),36000,int(step*100))]
    
        a_array[a_array<0] = a_arraya_array[a_array<0]+360
    
        for i, m in enumerate(sectores):
            print 'Sector'+str(i)+'(max_threshold = '+str(m)+')'
            if i == 0:
                for b in a_array:
                    if b <= m or b > sectores[-1]:
                        print b
    
            else:
                for b in a_array:
                    if b <= m and b > sectores[i-1]:
                        print b
        return "it works!"
    
    # TESTING IF THE FUNCTION IS WORKING:
    a = numpy.array([2,67,89,3,245,359,46,342])
    
    print wind_sectors(a, 16)
    
    # WITH NDARRAYS:
    
    b = numpy.array([[250,31,27,306], [142,54,260,179], [86,93,109,311]])
    
    print wind_sectors(b.flat[:], 16) 
    

    about flat and reshape functions:

    >>> a = numpy.array([[0,1,2,3], [4,5,6,7], [8,9,10,11]])
    >>> original = a.shape
    >>> b = a.flat[:]
    >>> c = b.reshape(original)
    >>> a
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11]])
    >>> b
    array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
    >>> c
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to calculate the within and between run variances from some data as
I am trying to write some code to calculate dividend yields. I need to
I need to calculate the direction of dragging a touch, to determine if the
I am working on a project where I need to calculate some numbers in
Hai i have an excel sheet, in that i need to calculate some values
I am creating a boxplot generator in Ruby, and I need to calculate some
to calculate some longitude and latitude values I need more decimal places like mysql
I'm working on a disk space calculator and i need to dynamically calculate some
I need to calculate sum of occurences of some data in two columns in
In some scenario I need to calculate the number of words in a particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.