Return a boolean array which is True where the string element in array ends with suffix in Python Last Updated : 06 Feb, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we are going to see how we will return a boolean array which is True where the string element in the array ends with a suffix in Python. numpy.char.endswith() numpy.char.endswith() return True if the elements end with the given substring otherwise it will return False. Syntax : np.char.endswith(input_numpy_array,'substring') Parameters: input_numpy_array refers to the numpy array with strings substring is compared with all elements present in an array Return: Return the boolean array which includes "True" if a substring is present as a suffix and "False" if a substring is not present as a suffix. Example 1: In this example, we are creating a NumPy array with 5 strings and checking the elements' ends with 'ks'. Python3 # import numpy import numpy as np # Create 1D array of strings. a = np.array(['hello', 'welcome to', 'geeks', 'for', 'geeks']) # check the strings in an above array # ends with substring - 'ks' # and stored in a variable "gfg". Data = np.char.endswith(a, 'ks') # Print boolean array print(Data) Output: [False False True False True] Example 2: In this example, we are creating a NumPy array with 5 strings and checking the element's ends with 'o'. Python3 # import numpy import numpy as np # Create 1D array of strings. a = np.array(['hello', 'welcome to', 'geeks', 'for', 'geeks']) # check the strings in an above array # ends with substring - 'o' # and stored in a variable "gfg". Data = np.char.endswith(a, 'o') # Print boolean array print(Data) Output: [ True True False False False] Time complexity: O(N), where N is the number of strings in the array "a". Space complexity : O(N), as we are storing the result in a boolean array "Data" with the same number of elements as the number of strings in the array "a". Comment More infoAdvertise with us Next Article Return a boolean array which is True where the string element in array ends with suffix in Python sravankumar_171fa07058 Follow Improve Article Tags : Python Practice Tags : python Similar Reads How to Return a Boolean Array True Where the String Array Ends with Suffix Using NumPy? In this article, we will discuss how to return a boolean array that is True where the string element in the array ends with a suffix using NumPy in Python. Example: Check the array ends with Com Input: [email protected] Output: True Input: [email protected] Output: False In Python, numpy.char module pr 2 min read How to invert the elements of a boolean array in Python? Given a boolean array the task here is to invert its elements. A boolean array is an array which contains only boolean values like True or False, 1 or 0. Input : A=[true , true , false] Output: A= [false , false , true] Input: A=[0,1,0,1] Output: A=[1,0,1,0] Method 1: You can use simple if else me 2 min read Test whether the elements of a given NumPy array is zero or not in Python In numpy, we can check that whether none of the elements of given array is zero or not with the help of numpy.all() function. In this function pass an array as parameter. If any of one element of the passed array is zero then it returns False otherwise it returns True boolean value. Syntax: numpy.al 2 min read Python - Filter the List of String whose index in second List contains the given Substring Given two lists, extract all elements from the first list, whose corresponding index in the second list contains the required substring. Examples: Input : test_list1 = ["Gfg", "is", "not", "best", "and", "not", "CS"], test_list2 = ["Its ok", "all ok", "wrong", "looks ok", "ok", "wrong", "thats ok"], 10 min read How to check whether the elements of a given NumPy array is non-zero? In NumPy with the help of any() function, we can check whether any of the elements of a given array in NumPy is non-zero. We will pass an array in the any() function if it returns true then any of the element of the array is non zero if it returns false then all the elements of the array are zero. S 1 min read How to Fix âValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()â If we work with NumPy or Pandas in Python, we might come across the ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() error. In this article, we will the reason as well as the solution to fix this error. ValueError: The truth value of an array wi 6 min read How to check whether specified values are present in NumPy array? Sometimes we need to test whether certain values are present in an array. Using Numpy array, we can easily find whether specific values are present or not. For this purpose, we use the "in" operator. "in" operator is used to check whether certain element and values are present in a given sequence an 2 min read Check If Dictionary Value Contains Certain String with Python We need to check if the value associated with a key in a dictionary contains a specific substring. For example, if we have a dictionary of user profiles and we want to check if any userâs description contains a particular word, we can do this easily using various methods. Letâs look at a few ways to 4 min read Python | Filter String with substring at specific position Sometimes, while working with Python string lists, we can have a problem in which we need to extract only those lists that have a specific substring at a specific position. This kind of problem can come in data processing and web development domains. Let us discuss certain ways in which this task ca 7 min read Check whether a Numpy array contains a specified row In this article we will learn about checking a specified row is in NumPy array or not. If the given list is present in a NumPy array as a row then the output is True else False. The list is present in a NumPy array means any row of that numpy array matches with the given list with all elements in gi 2 min read Like