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 6889355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:08:45+00:00 2026-05-27T06:08:45+00:00

I have this numpy array: a = np.array([[[1,2,3],[-1,-2,-3]],[[4,5,6],[-4,-5,-6]]]) b is a transpose of a

  • 0

I have this numpy array:

a = np.array([[[1,2,3],[-1,-2,-3]],[[4,5,6],[-4,-5,-6]]])

b is a transpose of a. I want b be like this:

b = np.array([[[1,-1],[2,-2],[3,-3]],[[4,-4],[5,-5],[6,-6]]])

Is it possible to do it in one line?


EDIT:

And if I have this instead:

a = np.empty(3,dtype = object)

a[0] = np.array([[1,2,3],[-1,-2,-3]])

a[1] = np.array([[4,5,6],[-4,-5,-6]])

How can I get b?

  • 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-27T06:08:45+00:00Added an answer on May 27, 2026 at 6:08 am

    You can do it using np.transpose(a,(0,2,1)):

    In [26]: a = np.array([[[1,2,3],[-1,-2,-3]],[[4,5,6],[-4,-5,-6]]])
    
    In [27]: b = np.transpose(a,(0,2,1))
    
    In [28]: print a
    [[[ 1  2  3]
      [-1 -2 -3]]
    
     [[ 4  5  6]
      [-4 -5 -6]]]
    
    In [29]: print b
    [[[ 1 -1]
      [ 2 -2]
      [ 3 -3]]
    
     [[ 4 -4]
      [ 5 -5]
      [ 6 -6]]]
    

    For your edited question with an array of dtype=object — there is no direct way to compute the transpose, because numpy doesn’t know how to transpose a generic object. However, you can use list comprehension and transpose each object separately:

    In [90]: a = np.empty(2,dtype = object)
    
    In [91]: a[0] = np.array([[1,2,3],[-1,-2,-3]])
    
    In [92]: a[1] = np.array([[4,5,6],[-4,-5,-6]])
    
    In [93]: print a
    [[[ 1  2  3]
     [-1 -2 -3]] [[ 4  5  6]
     [-4 -5 -6]]]
    
    In [94]: b = np.array([np.transpose(o) for o in a],dtype=object)
    
    In [95]: print b
    [[[ 1 -1]
      [ 2 -2]
      [ 3 -3]]
    
     [[ 4 -4]
      [ 5 -5]
      [ 6 -6]]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My vertices are interleaved in a numpy array (dtype = float32) like this: ...
Assuming I have a numpy array like: [1,2,3,4,5,6] and another array: [0,0,1,2,2,1] I want
I have a NumPy array, i want to accumulate the values of one column,
I have a one dimensional NumPy array: a = numpy.array([2,3,3]) I would like to
I have an array like this numpy array dd= [[foo 0.567 0.611] [bar 0.469
I have an array like this numpy array dd =[[0.567 2 0.611] [0.469 1
I have a Numpy array that looks like >>> a array([[ 3. , 2.
I have a very large numpy array (containing up to a million elements) like
This is a simplification of my question. I have a numpy array: x =
How does one add rows to a numpy array? I have an array A:

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.