w10schools
Login Register
  • Home
  • Tutorials
    • HTML, CSS
      • HTML, HTML5
      • CSS, CSS3
    • XML
    • JavaScript, AJAX
    • PHP
    • Ruby on Rails
      • Ruby
      • Rails
    • ASP.NET
      • ASP
      • C# .NET
    • Java
      • JSP
    • Databases
      • MySQL
      • MSSQL Server
      • Oracle
    • Web Server
      • Windows
      • Linux
      • Apache
      • IIS
    • Design
      • Dreamweaver
      • Flash
      • Photoshop
      • Fireworks
      • CorelDRAW
      • Illustrator
  • References
    • HTML
      • Bootstrap
    • CSS
      • CSS Selectors
      • Sass
    • JavaScript
    • Mobile Apps
      • Cordova
    • Ruby on Rails
      • Ruby
      • Rails
    • PHP
      • Function
      • Language
      • CodeIgniter
      • Phalcon
      • PHPUnit
      • Symfony
      • Drupal
      • Yii
      • Laravel
    • Perl
      • Perl
    • Python
      • Python
      • Django
      • NumPy
      • Pandas
      • scikit-image
      • scikit-learn
      • Statsmodels
      • Matplotlib
    • Lua
      • Lua
    • C, C++
      • C
      • C++
    • Server
      • Docker
      • Apache HTTP Server
      • Nginx
    • Database
      • PostgreSQL
    • Big Data
      • TensorFlow
    • Game Development
      • Phaser
      • LÖVE
  • Articles
    • News
    • General
      • Website Promotion
      • Online Advertising
      • Make Money Online
    • Editorials
    • Interviews
    • Web Roundups
  • Resources
    • Design
      • Fonts
      • Graphics
      • Vectors
      • Templates
      • UI (User Interface)
      • Brushes
      • Patterns, Backgrounds
      • Textures
    • Web Development
      • HTML, CSS
      • XML
      • JavaScript, AJAX
      • Ruby on Rails
      • PHP
      • Java
      • .NET
      • Python
      • Perl
      • Flash
    • Mobile Application Development
      • Mobile Development Tools
      • Swift
    • Online Services
      • Online Storage
      • Web Hosting
  • Tools
    • Generators
Edit
In Place Editing Advanced Editing
  • References
  • Python
  • NumPy
  • Routines
  • Sorting, searching, and counting

numpy.count_nonzero()

numpy.count_nonzero(a)

Counts the number of non-zero values in the array a.

Parameters:

a : array_like

The array for which to count non-zeros.

Returns:

count : int or array of int

Number of non-zero values in the array.

See also

nonzero
Return the coordinates of all the non-zero values.

Examples

>>> np.count_nonzero(np.eye(4))
4
>>> np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]])
5
Links:
  • https://docs.scipy.org/doc/numpy-1.11.0/reference/generated/numpy.count_nonzero.html
doc_NumPy
doc_NumPy
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.

Popular Articles
numpy.nonzero() numpy.nonzero(a) [source] Return the indices of the elements that are non-zero. Returns a tuple of arrays, one for each dimension of a, containin
numpy.ma.nonzero() numpy.ma.nonzero(self) = Return the indices of unmasked elements that are not zero. Returns a tuple of arrays, one for each dimension, containin
numpy.ma.count() numpy.ma.count(a, axis=None) [source] Count the non-masked elements of the array along the given axis. Parameters: axis : int, optional Axis al
nonzero? num.nonzero? â self or nil Instance Public methods Returns self if num is not zero, nil otherwise. This behavior is useful when chain
nonzero? nonzero?() Instance Public methods Returns self if the value is non-zero, nil otherwise.


Return to View
  • Facebook
  • Tweet
  • Digg it
  • Stumbleupon
  • Delicious
  • Plus Share

Designed by : w10schools

service@w10schools.com

Our Partners: aeeble – Providing content publishing and search solutions