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 Like