numpy.nanargmax() in Python Last Updated : 19 Sep, 2023 Comments Improve Suggest changes Like Article Like Report The numpy.nanargmax() function returns indices of the max element of the array in a particular axis ignoring NaNs. The results cannot be trusted if a slice contains only NaNs and Infs. Syntax: numpy.nanargmax(array, axis = None) Parameters : array : Input array to work on axis : [int, optional]Along a specified axis like 0 or 1 Return : Array of indices into the array with same shape as array.shape with the dimension along axis removed. Code 1 : Python # Python Program illustrating # working of nanargmax() import numpy as geek # Working on 1D array array = [geek.nan, 4, 2, 3, 1] print("INPUT ARRAY 1 : \n", array) array2 = geek.array([[geek.nan, 4], [1, 3]]) # returning Indices of the max element # as per the indices ingnoring NaN print("\nIndices of max in array1 : ", geek.nanargmax(array)) # Working on 2D array print("\nINPUT ARRAY 2 : \n", array2) print("\nIndices of max in array2 : ", geek.nanargmax(array2)) print("\nIndices at axis 1 of array2 : ", geek.nanargmax(array2, axis = 1)) Output : INPUT ARRAY 1 : [nan, 4, 2, 3, 1] Indices of max in array1 : 1 INPUT ARRAY 2 : [[ nan 4.] [ 1. 3.]] Indices of max in array2 : 1 Indices at axis 1 of array2 : [1 1] Code 2: Comparing working of argmax and nanargmax Python # Python Program illustrating # working of nanargmax() import numpy as geek # Working on 2D array array = ( [[ 8, 13, 5, 0], [ 16, geek.nan, 5, 3], [geek.nan, 7, 15, 15], [3, 11, 4, 12]]) print("INPUT ARRAY : \n", array) # returning Indices of the max element # as per the indices ''' [[ 8 13 5 0] [ 16 2 5 3] [10 7 15 15] [ 3 11 4 12]] ^ ^ ^ ^ ''' print("\nIndices of max using argmax : ", geek.argmax(array, axis = 0)) print("\nIndices of max using nanargmax : : ", geek.nanargmax(array, axis = 0)) Output : INPUT ARRAY : [[8, 13, 5, 0], [16, nan, 5, 3], [nan, 7, 15, 15], [3, 11, 4, 12]] Indices of max using argmax : [2 1 2 2] Indices of max using nanargmax : : [1 0 2 2] 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.nanargmax() in Python M Mohit Gupta_OMG Improve Article Tags : Misc Python Python-numpy Python numpy-Sorting Searching 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