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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:16:23+00:00 2026-06-15T12:16:23+00:00

Say I have a matrix in a numpy array in Python In [3]: my_matrix

  • 0

Say I have a matrix in a numpy array in Python

In [3]: my_matrix
Out[3]: 
array([[ 2.,  2.,  2.,  2.,  2.,  2.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  2.,  2.,  2.,  2.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  2.,  2.,  2.,
         2.,  2.,  2.,  2.,  2.]])

Is there a way to have Python/IPython print my array as:

[ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2; 
  0 0 0 0 0 0 2 2 2 2 0 0 0 0 0 0 0 0; 
  0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 ]

? (~ similar to the way MATLAB does it)

Also, I have noticed that IPython does not use the full width of my terminal when printing numpy arrays. Other functions do (e.g. pprint.pprint). How can I change that?

  • 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-15T12:16:24+00:00Added an answer on June 15, 2026 at 12:16 pm

    Use numpy.set_printoptions. For increasing the line width:

    np.set_printoptions(linewidth=150)
    

    Replace 150 by whatever you need. Now, to print as you asked (I guess it means without the decimal point):

    print my_matrix.astype('i')
    

    If you have floating point values you can also control the precision for printouts with the option precision:

    np.set_printoptions(precision=3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a 2D matrix,Is there a particular algorithm or way to do
Say in Matlab I have a matrix like this: 1 2 3 4 5
Say I have a numpy matrix like so: [[ x1, x2, x3, ... ],
let's say I have a matrix (array) like this example, but much larger: 0
Possible Duplicate: Matrix Transpose in Python I have a matrix, say A = [[0,0],[1,1]]
Say I have a matrix: from numpy import * a = zeros(shape=(nRows,nColumns)); and I
Say I have a huge numpy matrix A taking up tens of gigabytes. It
Say I have a 1D array converted from a MxN 2D matrix, and I
Let's say I have a matrix with all 0's with the exception of the
So let's say I have a matrix, mdat and I only know the index

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.