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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:14:46+00:00 2026-06-18T00:14:46+00:00

I have a Numpy matrix, for example, numpy.matrix([[-1, 2],[1, -2]], dtype=’int’) . I want

  • 0

I have a Numpy matrix, for example, numpy.matrix([[-1, 2],[1, -2]], dtype='int'). I want to get its integer-valued eigenvectors, if any; for example, numpy.array([[-1], [1]]) for the above matrix. What Numpy returns are eigenvectors in floating numbers, scaled to have unit length.

One can do this in Sage, where one can specify the field (i.e., data type) of the matrix and operations done on the matrix will respect the field one specifies.

Any idea of how to do this nicely in Python? Many thanks in advance.

  • 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-18T00:14:47+00:00Added an answer on June 18, 2026 at 12:14 am

    I am personally content with the following solution: I called sage in Python and let sage compute what I want. sage, being math-oriented, is rather versatile in computations involving fields other than reals.

    Below is my script compute_intarrs.py and it requires sage be installed. Be aware it is a little slow.

    import subprocess
    import re
    import numpy as np
    
    # construct a numpy matrix
    mat = np.matrix([[1,-1],[-1,1]])
    # convert the matrix into a string recognizable by sage
    matstr = re.sub('\s|[a-z]|\(|\)', '', mat.__repr__())
    
    # write a (sage) python script "mat.py";
    # for more info of the sage commands: 
    # www.sagemath.org/doc/faq/faq-usage.html#how-do-i-import-sage-into-a-python-script
    # www.sagemath.org/doc/tutorial/tour_linalg.html
    f = open('mat.py', 'w')
    f.write('from sage.all import *\n\n')
    f.write('A = matrix(ZZ, %s)\n\n' % matstr)
    f.write('print A.kernel()')  # this returns the left nullspace vectors
    f.close()
    
    # call sage and run mat.py
    p = subprocess.Popen(['sage', '-python', 'mat.py'], stdout=subprocess.PIPE)
    
    # process the output from sage
    arrstrs = p.communicate()[0].split('\n')[2:-1]
    arrs = [np.array(eval(re.sub('(?<=\d)\s*(?=\d|-)', ',', arrstr))) 
            for arrstr in arrstrs]
    print arrs
    

    Result:

    In [1]: %run compute_intarrs.py

    [array([1, 1])]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following numpy matrix that I want to sort in ascending order
I have a matrix in the type of a Numpy array. How would I
I have a NumPy array [1,2,3,4,5,6,7,8,9,10,11,12,13,14] and want to have an array structured like
Say I have a matrix in a numpy array in Python In [3]: my_matrix
I have a numpy matrix with shape of (4601, 58). I want to split
I am using numpy. I have one array Y and one matrix X .
In short: I have two matrices (or arrays): import numpy block_1 = numpy.matrix([[ 0,
I'm using Numpy and have a 7x12x12 matrix whose values I would like to
Are there any C++ (or C) libs that have NumPy-like arrays with support for
I have an numpy array which I save to a image using savefig(). Then

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.