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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:14:39+00:00 2026-05-19T09:14:39+00:00

This is my first post and I’m still a Python and Scipy newcomer, so

  • 0

This is my first post and I’m still a Python and Scipy newcomer, so go easy on me! I’m trying to convert an Nx1 matrix into a python list. Say I have some 3×1 matrix

x = scipy.matrix([1,2,3]).transpose()

My aim is to create a list, y, from x so that

y = [1, 2, 3]

I’ve tried using the tolist() method, but it returns [[1], [2], [3]], which isn’t the result that I’m after. The best i can do is this

y = [xi for xi in x.flat]

but it’s a bit cumbersome, and I’m not sure if there’s an easier way to achieve the same result. Like I said, I’m still coming to grips with Python and Scipy…

Thanks

  • 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-19T09:14:39+00:00Added an answer on May 19, 2026 at 9:14 am

    A question for your question

    While Sven and Navi have answered your question on how to convert

    x = scipy.matrix([1,2,3]).transpose()
    

    into a list, I’ll ask a question before answering:

    • Why are you using an Nx1 matrix instead of an array?

    Using array instead of matrix

    If you look at the Numpy for Matlab Users wiki/documentation page, section 3 discusses ‘array’ or ‘matrix’? Which should I use?. The short answer is that you should use array.

    One of the advantages of using an array is that:

    You can treat rank-1 arrays as either row or column vectors. dot(A,v) treats v as a column vector, while dot(v,A) treats v as a row vector. This can save you having to type a lot of transposes.

    Also, as stated in the Numpy Reference Documentation, "Matrix objects are always two-dimensional." This is why x.tolist() returned a nested list of [[1], [2], [3]] for you.

    Since you want an Nx1 object, I’d recommend using array as follows:

    >>> import scipy
    >>> x = scipy.array([1,2,3])
    >>> x
    array([1, 2, 3])
    >>> y = x.tolist()     // That's it. A clean, succinct conversion to a list.
    >>> y
    [1, 2, 3]
    

    If you really want to use matrix

    If for some reason you truly need/want to use a matrix instead of an array, here’s what I would do:

    >>> import scipy
    >>> x = scipy.matrix([1,2,3]).transpose()
    >>> x
    matrix([[1],
            [2],
            [3]])
    >>> y = x.T.tolist()[0]
    >>> y
    [1, 2, 3]
    

    In words, the x.T.tolist()[0] will:

    1. Transpose the x matrix using the .T attribute
    2. Convert the transposed matrix into a nested list using .tolist()
    3. Grab the first element of the nested listed using [0]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post on this rather spiffing website so go easy on
This is my first post. I'm trying to do some basic meta-programming with javascript,
This is my first post here and I wanted to get some input from
This is my first post and I'm quite a novice on C++ and compiling
Well, this is my first post here and really enjoying the site. I have
this is first post here and I am a noob programmer. This may be
This is my first post on StackOverflow, so please be gentle... I have some
this is my first post here. I'm using an existing Flash widget but would
this is my first post.. so I'm learning Android & Java (coming from Actionscript),
This is my first post on StackOverflow. This community has provided me with some

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.