- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Test element-wise for NaT (not a time) in Numpy
To test element-wise for NaT, use the numpy.isnat() method in Python Numpy. It checks the value for datetime or timedelta data type.
The condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
Steps
At first, import the required library −
import numpy as np
To test element-wise for NaT, use the numpy.isnat() method in Python Numpy. It checks the value for datetime or timedelta data type −
Checking for dates. The datetime64 data type accepts the string “NAT”, in any combination of lowercase/uppercase letters, for a “Not A Time” value −
print("Check for NaT? ", np.isnat(np.datetime64("NaT"))) print("Check for NaT? ", np.isnat(np.datetime64("2021-12-22"))) print("Check for NaT? ", np.isnat(np.datetime64('2021-12', 'D'))) print("Check for NaT? ", np.isnat(np.datetime64(1, 'Y'))) print("Check for NaT? ", np.isnat(np.datetime64('2005-02-25T03:30'))) print("Check for NaT? ", np.isnat(np.datetime64('nat'))) print("Check for NaT? ", np.isnat(np.datetime64("5"))) print("Check for NaT? ", np.isnat(np.datetime64('nAt')))
Example
import numpy as np # To test element-wise for NaT, use the numpy.nat() method in Python Numpy # It checks the for datetime or timedelta data type. # Checking for dates # The datetime64 data type accepts the string “NAT”, # in any combination of lowercase/uppercase letters, for a “Not A Time” value. print("Check for NaT? ", np.isnat(np.datetime64("NaT"))) print("Check for NaT? ", np.isnat(np.datetime64("2021-12-22"))) print("Check for NaT? ", np.isnat(np.datetime64('2021-12', 'D'))) print("Check for NaT? ", np.isnat(np.datetime64(1, 'Y'))) print("Check for NaT? ", np.isnat(np.datetime64('2005-02-25T03:30'))) print("Check for NaT? ", np.isnat(np.datetime64('nat'))) print("Check for NaT? ", np.isnat(np.datetime64("5"))) print("Check for NaT? ", np.isnat(np.datetime64('nAt')))
Output
Check for NaT? True Check for NaT? False Check for NaT? False Check for NaT? False Check for NaT? False Check for NaT? True Check for NaT? False Check for NaT? True
- Related Articles
- Test array values for NaT (not a time) in Numpy
- Test element-wise for NaN in Numpy
- Test element-wise for positive or negative infinity in Numpy
- Compute the bit-wise NOT of an array element-wise in Numpy
- Compute the bit-wise NOT of a One-Dimensional array element-wise in Numpy
- Compute the bit-wise NOT of a Two-Dimensional array element-wise in Numpy
- Test array values for NaT and store the result in a new location in Numpy
- Subtract arguments element-wise in Numpy
- Compute the truth value of NOT an array element-wise in Numpy
- True Divide arguments element-wise in Numpy
- Return element-wise string concatenation for two arrays of string in Numpy
- Calculate the absolute value element-wise in Numpy
- Return element-wise string multiple concatenation in Numpy
- Compute the bit-wise AND of two arrays element-wise in Numpy
- Test finiteness (not infinity and not Not a Number) in Numpy
