Wednesday, June 22, 2022
HomeWordPress DevelopmentReturn a boolean array which is True the place the string ingredient...

Return a boolean array which is True the place the string ingredient in array ends with suffix in Python


View Dialogue

Enhance Article

Save Article

Like Article

On this article, we’re going to see how we are going to return a boolean array which is True the place the string ingredient within the array ends with a suffix in Python.

numpy.char.endswith()

numpy.char.endswith() return True if the weather finish with the given substring in any other case it is going to return False.

Syntax : np.char.endswith(input_numpy_array,’substring’)

Parameters:

  •  input_numpy_array refers back to the numpy array with strings
  •  substring is in contrast with all parts current in an array

Return: Return the boolean array which incorporates “True” if a substring is current as a suffix and “False” if a substring isn’t current as a suffix.

Instance 1: 

On this instance, we’re making a NumPy array with 5 strings and checking the weather’ ends with ‘ks’.

Python3

import numpy as np

  

a = np.array(['hello', 'welcome to',

              'geeks', 'for', 'geeks'])

  

Information = np.char.endswith(a, 'ks')

  

print(Information)

Output:

[False False  True False  True]

Instance 2:

On this instance, we’re making a NumPy array with 5 strings and checking the ingredient’s ends with ‘o’.

Python3

import numpy as np

  

a = np.array(['hello', 'welcome to'

              'geeks', 'for', 'geeks'])

  

Information = np.char.endswith(a, 'o')

  

print(Information)

Output:

[ True  True False False False]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments