Session.filter(self, pattern=None, kind=None)[source]

Returns a new session with objects which match some criteria.

patternstr, optional

Only keep arrays whose key match pattern.

  • ? matches any single character

  • * matches any number of characters

  • [seq] matches any character in seq

  • [!seq] matches any character not in seq

kind(tuple of) type, optional

Only keep objects which are instances of type(s) kind.


The filtered session.


>>> axis = Axis('a=a0..a2')
>>> group = axis['a0,a1'] >> 'a01'
>>> test1, zero1 = ndtest((2, 2)), zeros((3, 2))
>>> s = Session([('test1', test1), ('zero1', zero1), ('axis', axis), ('group', group)])

Filter using a pattern argument

>>> # get all items with names ending with '1'
>>> s.filter(pattern='*1').names
['test1', 'zero1']
>>> # get all items with names starting with letter in range a-k
>>> s.filter(pattern='[a-k]*').names
['axis', 'group']

Filter using kind argument

>>> s.filter(kind=Axis).names
>>> s.filter(kind=(Axis, Group)).names
['axis', 'group']