API reference

This module provides class NList, a multidimensional list.

Indexes and shapes used with NList must be tuples. Example:

l = nlist.NList(shape=(2, 3))
l[1, 2] = 42

NList’s shape can be an empty tuple meaning a zero-dimensional list that has one element with index ().

NList converts to False only if its size is 0, meaning that at least one of its dimensions is 0. Note that the size of a zero-dimensional NList is 1.

An NList equals another NList if their shapes and all their elements are equal.

NList is an iterable of all its elements.

Whenever an ordering of indexes is implied, standard tuple comparison semantics are used.

class nlist.NList(other=None, shape=None, default=None)

Initialize NList either from another multidimensional structure or by shape and default value.

Parameters:
  • other – Either an another NList or a nested sequence to copy data from. For instance, if other is [[1, 2, 3], [4, 5, 6]], a 2x3 NList will be created with this data.
  • shape (tuple) – A tuple of dimension sizes. E.g. (2, 3) for 2x3 NList.
  • default – A value to fill the NList with when shape is passed.

other and shape/default arguments are mutually exclusive

copy()

Returns a shallow copy of the NList.

Return type:NList
count(value)

Returns the number of occurrences of value in the NList.

Return type:int
enumerate()

Return an iterable of all pairs (index, value) in the NList.

index(value, start=None, stop=None)

Returns index of the first occurrence of value in the NList.

Parameters:
  • value – A value to search for.
  • start (tuple) – An index to start the search from.
  • stop (tuple) – An index before which to stop search.
Raises ValueError:
 

If the value is not found.

Return type:

tuple

start and stop must be valid indexes for the NList, or None.

keys(start=None, stop=None)

Returns an iterable of all indexes valid for the NList.

Parameters:
  • start (tuple) – An index to start iteration from.
  • stop (tuple) – An index before which to stop iteration.

start and stop must be valid indexes for the NList, or None.

rank

Number of the NList’s dimensions. Read-only.

shape

A tuple with the NList’s dimensions. Read-only.

size

Number of elements in the NList. Read-only.

Previous topic

Welcome to nlist’s documentation!

This Page