numpy.isinf() in Python Last Updated : 08 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The numpy.isinf() function tests element-wise whether it is +ve or -ve infinity or not return the result as a boolean array. Syntax: numpy.isinf(array [, out]) Parameters : array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array placed with result. Its type is preserved and it must be of the right shape to hold the output. Return : boolean array containing the result. For scalar input, the result is a new boolean with value True if the input is positive or negative infinity; otherwise the value is False. For array input, the result is a boolean array with the same shape as the input and the values are True where the corresponding element of the input is positive or negative infinity; elsewhere the values are False. Code 1 : Python # Python Program illustrating # numpy.isinf() method import numpy as geek print("Finite : ", geek.isinf(1), "\n") print("Finite : ", geek.isinf(0), "\n") # not a number print("Finite : ", geek.isinf(geek.nan), "\n") # infinity print("Finite : ", geek.isinf(geek.inf), "\n") print("Finite : ", geek.isinf(geek.NINF), "\n") x = geek.array([-geek.inf, 0., geek.inf]) y = geek.array([2, 2, 2]) print("Checking for infinity : ", geek.isinf(x, y)) Output : Finite : False Finite : False Finite : False Finite : True Finite : True Checking for infinity : [1 0 1] Code 2 : Python # Python Program illustrating # numpy.isinf() method import numpy as geek # Returns True/False value for each element b = geek.arange(8).reshape(2, 4) print("\n",b) print("\nIs Infinity : \n", geek.isinf(b)) # geek.inf : Positive Infinity # geek.NINF : negative Infinity b = [[geek.inf], [geek.NINF]] print("\nIs Infinity : \n", geek.isinf(b)) Output : [[0 1 2 3] [4 5 6 7]] Is Infinity : [[False False False False] [False False False False]] Is Infinity : [[ True] [ True]] Note : These codes won't run on online IDE's. So please, run them on your systems to explore the working. Comment More infoAdvertise with us Next Article numpy.isinf() in Python M Mohit Gupta_OMG Improve Article Tags : Misc Python Python-numpy Python numpy-Logic Functions Practice Tags : Miscpython Similar Reads Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth 15+ min read SQL Commands | DDL, DQL, DML, DCL and TCL Commands SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e 7 min read Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p 11 min read TCP/IP Model The TCP/IP model (Transmission Control Protocol/Internet Protocol) is a four-layer networking framework that enables reliable communication between devices over interconnected networks. It provides a standardized set of protocols for transmitting data across interconnected networks, ensuring efficie 7 min read Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list 10 min read Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test 9 min read Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co 11 min read Basics of Computer Networking A computer network is a collection of interconnected devices that share resources and information. These devices can include computers, servers, printers, and other hardware. Networks allow for the efficient exchange of data, enabling various applications such as email, file sharing, and internet br 14 min read Enumerate() in Python enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam 3 min read Like