turicreate.SArray.contains

SArray.contains(item)

Performs an element-wise search of “item” in the SArray.

Conceptually equivalent to:

>>> sa.apply(lambda x: item in x)

If the current SArray contains strings and item is a string. Produces a 1 for each row if ‘item’ is a substring of the row and 0 otherwise.

If the current SArray contains list or arrays, this produces a 1 for each row if ‘item’ is an element of the list or array.

If the current SArray contains dictionaries, this produces a 1 for each row if ‘item’ is a key in the dictionary.

Parameters:
item : any type

The item to search for.

Returns:
out : SArray

A binary SArray where a non-zero value denotes that the item was found in the row. And 0 if it is not found.

See also

is_in

Examples

>>> SArray(['abc','def','ghi']).contains('a')
dtype: int
Rows: 3
[1, 0, 0]
>>> SArray([['a','b'],['b','c'],['c','d']]).contains('b')
dtype: int
Rows: 3
[1, 1, 0]
>>> SArray([{'a':1},{'a':2,'b':1}, {'c':1}]).contains('a')
dtype: int
Rows: 3
[1, 1, 0]