How do I print the full NumPy array without truncation?
Directly modify the print options for NumPy with numpy.set_printoptions
and set threshold=sys.maxsize
. This will print all elements of the array, no omission:
Bypassing truncation, context managers, and print functionality
Let's get into more fine-tuned control over printing arrays!
Convert array to list
Escape the bonds of NumPy's print rules by turning your array into a plain-old Python list:
Use context managers
Need a once-off sneak peek of the full array without changing global settings? Utilize **np.printoptions
**:
After this block, settings seamlessly revert to original. No strings attached!
Define fullprint
function for frequent use
Encapsulate above within a function. This is handy when you find yourself needing to print full arrays frequently:
Pretty print with pprint
When working with complex, multidimensional arrays, enlist the help of pprint
:
Creating large scale testing arrays
Experiment your new-found print powers on larger arrays using **numpy.arange
** and reshape
:
Hands-on with printoptions parameters
NumPy's printoptions
packs more tools than just threshold
. For instance:
precision
: controls decimal places for floating-point numbers.suppress
: toggle to display small numbers without scientific notation.formatter
: for advanced tweaks in how arrays are printed.
Was this article helpful?