turicreate.SArray.filter — Turi Create API 6.4.1 documentation (original) (raw)

SArray. filter(fn, skip_na=True, seed=None)

Filter this SArray by a function.

Returns a new SArray filtered by this SArray. If fn evaluates an element to true, this element is copied to the new SArray. If not, it isn’t. Throws an exception if the return type of fn is not castable to a boolean value.

Parameters: fn : function Function that filters the SArray. Must evaluate to bool or int. skip_na : bool, optional If True, will not apply fn to any undefined values. seed : int, optional Used as the seed if a random number generator is included in fn.
Returns: out : SArray The SArray filtered by fn. Each element of the SArray is of type int.

Examples

sa = turicreate.SArray([1,2,3]) sa.filter(lambda x: x < 3) dtype: int Rows: 2 [1, 2]