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

  • SEARCH
  • Home
  • 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 6196683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:41:13+00:00 2026-05-24T03:41:13+00:00

I have following arrays. In [1]: a = np.array([[aa, bb, cc], [cc, bb, aa]])

  • 0

I have following arrays.

In [1]: a = np.array([["aa", "bb", "cc"], ["cc", "bb", "aa"]])
In [2]: a
Out[2]:
array([['aa', 'bb', 'cc'],
       ['cc', 'bb', 'aa']],
       dtype='|S2')

In [3]: b = np.array([[11, 12, 13], [21, 22, 23]])
In [4]: b
Out[4]:
array([[11, 12, 13],
       [21, 22, 23]])

Relation between a and b can be described conceptually as b[0].aa = 11 b[0].bb = 12. b[0].cc = 13. i.e. row in ‘a’ are keys and row in ‘b’ are values of a single dict. First rows will represent

{'aa': 11, 'bb': 12, 'cc': 13}

Now we are given with keys of these dicts.

In [5]: c = np.array(["bb", "aa"])
In [6]: c
Out[6]:
array(['bb', 'aa'],
  dtype='|S2')

Now, what is the best way of accessing b array given ‘c’ which will give axis of each row as value in ‘a’. One way to do is

In [7]: cond_list = [a[:, 0] == c,  a[:, 1] == c, a[:, 2] == c]
In [8]: choice_list = [b[:, 0],  b[:, 1], b[:, 2]]
In [9]: np.select(cond_list, choice_list)
Out[9]: array([12, 23])

Is there a better way of doing it? What if number of axis in a and b are not known before hand?

  • 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-05-24T03:41:14+00:00Added an answer on May 24, 2026 at 3:41 am
    In [13]: a==c[:,np.newaxis]
    Out[13]: 
    array([[False,  True, False],
           [False, False,  True]], dtype=bool)
    
    In [14]: b[a==c[:,np.newaxis]]
    Out[14]: array([12, 23])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an array out of three arrays in the following
I have the following loop that renders an array a of arrays. Each arrays
I have the following method: -(void)testAPIModule { self.requests = [NSMutableArray array]; NSLog(@making arrays); /*(A)*/
I have the following array: Array( [0] => 0,0 [1] => 0,1 [2] =>
I have the following array structure: Array ( [0] => Array ( [configuration_id] =>
I have following array, that I need to operate by hand on bitmaps. const
I have the following array as3 example: var arrayDefinitionsargsAmfPhp:Array = new Array(); arrayDefinitionsargsAmfPhp['tabela'] =
I have the following arrays in PHP (okay they are a bit bigger but
I have the following array. <cfset ItemHasUsers = arrayNew(1)> <cfloop query=qReadData> <cfset ItemHasUsers[qReadData.currentrow][ID] =
I have the following array, $myarray[0]['first_name'] $myarray[0]['last_name'] I want to turn it into: $myarray['first_name']

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.