GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python NumPy: Increase the number of items (10 edge elements) shown by the print statement - w3resource

NumPy: Increase the number of items (10 edge elements) shown by the print statement

Last update on August 29 2025 12:45:24 (UTC/GMT +8 hours)


Print extended edges of a random 90x30 array.

Write a NumPy program to create a 90x30 array filled with random point numbers, increase the number of items (10 edge elements) shown by the print statement.

Sample Solution:

Python Code:

# Importing NumPy library
import numpy as np

# Generating a random array of integers between 0 and 9 with a shape of (90, 30)
nums = np.random.randint(10, size=(90, 30))

# Displaying the original array
print("Original array:")
print(nums)

# Increasing the number of edge items shown in the print statement to 10
np.set_printoptions(edgeitems=10)

# Displaying the array with increased number of edge items
print("\nIncrease the number of items (10 edge elements) shown by the print statement:")
print(nums) 

Sample Output:

Original array:
[[1 8 3 ... 9 5 8]
 [1 9 6 ... 6 5 0]
 [0 0 8 ... 6 9 8]
 ...
 [2 3 9 ... 4 0 1]
 [2 6 8 ... 8 3 4]
 [1 2 9 ... 7 4 8]]

Increase the number of items (10 edge elements) shown by the print statement:
[[1 8 3 0 1 2 8 0 0 5 ... 1 3 8 1 1 7 5 9 5 8]
 [1 9 6 1 0 7 7 3 8 6 ... 5 9 9 9 9 7 2 6 5 0]
 [0 0 8 1 4 2 1 3 2 9 ... 5 6 4 1 4 9 0 6 9 8]
 [7 2 7 1 7 2 4 7 2 0 ... 4 2 6 2 6 4 4 0 6 7]
 [3 6 0 0 2 1 6 6 2 9 ... 3 4 1 9 5 7 4 4 6 7]
 [9 5 2 6 9 2 7 7 9 6 ... 4 3 5 2 7 0 6 0 2 7]
 [5 5 4 1 9 2 5 3 5 2 ... 7 4 7 5 5 7 3 0 1 8]
 [5 9 9 9 6 3 5 0 9 4 ... 6 4 9 7 8 7 2 5 9 4]
 [6 1 0 8 9 8 0 6 6 3 ... 5 3 1 6 1 5 2 9 8 3]
 [3 0 3 1 4 1 4 1 9 6 ... 3 9 4 4 5 0 2 0 8 0]
 ...
 [3 9 5 0 3 8 5 3 1 1 ... 1 2 4 6 2 4 5 0 0 5]
 [7 9 7 0 1 3 0 1 8 4 ... 5 7 5 4 7 2 0 2 3 0]
 [4 2 6 4 7 2 3 9 7 9 ... 2 7 1 2 5 7 5 4 0 2]
 [7 8 9 7 3 3 1 2 8 5 ... 1 9 9 5 5 2 3 5 0 1]
 [3 7 6 8 3 2 5 0 5 4 ... 0 4 9 8 5 3 2 1 3 3]
 [3 3 8 4 0 4 8 4 7 0 ... 7 5 0 9 7 8 2 0 7 9]
 [8 4 4 7 3 8 2 0 8 9 ... 5 5 8 1 5 6 0 6 5 0]
 [2 3 9 9 9 8 6 5 4 4 ... 4 0 7 1 8 6 7 4 0 1]
 [2 6 8 7 3 3 8 4 1 6 ... 1 3 9 5 0 1 4 8 3 4]
 [1 2 9 5 1 2 9 9 5 4 ... 3 1 2 6 1 4 4 7 4 8]]

Explanation:

In the above code -

nums = np.random.randint(10, size=(90, 30)): This line creates a 90x30 NumPy array filled with random integers between 0 and 9, inclusive.

np.set_printoptions(edgeitems=10): This line sets the print options for NumPy arrays to display 10 edge items when printing the array.

print(nums): Finally print() function prints the 90x30 NumPy array according to the print options set in the previous step.


For more Practice: Solve these Related Problems:

  • Write a NumPy program to adjust np.set_printoptions so that a large 2D array displays 10 elements at each edge.
  • Create a function that prints a 90x30 array with its beginning and ending rows and columns fully shown, while the middle is truncated.
  • Implement a solution that temporarily increases the print threshold to reveal more elements, then resets it to default.
  • Test the extended print settings on arrays of various sizes to confirm the edge elements are correctly displayed.

Go to:

  • NumPy Array Exercises Home ↩
  • NumPy Exercises Home ↩

PREV : Remove specific columns from a 2D array.
NEXT : Compute element-wise arithmetic mean of two arrays.


Python-Numpy Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.