12

This question is different from this one: How to print the full NumPy array, without truncation?

In that question, the user wanted to know how to print the full array without truncation. I can print the array without truncation just fine. My problem is that only a small portion of the screen width is used. When trying to inspect large adjacency matrices, it's impossible to inspect them when the rows unnecessarily wrap.

I'm asking this question here because it always takes me hours to find the solution, and I want to disambiguate it from that answer post above.

For example:

import networkx as nx
import numpy as np
np.set_printoptions(threshold=np.inf)
graph = nx.gnm_random_graph(20, 20, 1)
nx.to_numpy_matrix(graph)

This output displays as:

Jupyter Notebook Numpy - Array Wrapping

3
  • 9
    np.set_printoptions( linewidth=100) or whatever Commented Apr 2, 2019 at 2:55
  • Write your own good old print_as_you_like_to_see_it() function maybe? Commented Apr 2, 2019 at 3:16
  • Answered a similar question here: stackoverflow.com/a/59058418/3857460. Commented Nov 26, 2019 at 20:05

1 Answer 1

18

Just gonna post NaN's comment as the answer:

Use np.set_printoptions(linewidth=n) where n has to do with the number of characters (not array elements) per line. So in your case n=100 should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.