Package Biskit :: Module SparseArray :: Class SparseArray
[hide private]
[frames] | no frames]

Class SparseArray

source code

Memory - saving representation of a sparse array.

Instance Methods [hide private]
  __init__(self, array_or_shape=0, typecode='f', default=0.)
Create a sparse array from a normal Numeric array or create an empty sparse array with a certain shape.
  __setAll_1D(self, a)
Replace content of this sparseArray with values from Numeric array or list of numbers -- only for 1-dimensional arrays.
  __setAll(self, a)
Replace content of this array with values from (multidimensional) Numeric array of numbers or list of lists (of lists..) of numbers.
str typecode(self)
Get type code of object.
number default(self)
Get default value, defined in __init__.
[ int ] nondefault(self)
Get a 1D list of indices that have a non-default value in a raveled version of this array.
[ number ] nondefault_values(self)
Get a 1D-list of all values != L.default() in the order that they would have in a raveled array.
array toarray(self)
Reconstruct dense array:
list tolist(self)
Reconstruct list from dense array:
  put(self, i, v)
Replace one or several values, L.put( i, v )
  __setMany(self, indices, values)
Add / replace values of the array.
int __pos(self, i)
Target position of given index in index list.
  __setitem__(self, i, v)
Set position specifyed by the index i to value v.
  __setitem_1D(self, i, v)
Set position specifyed by the index i to value v in a 1D array.
  __getitem_1D(self, i)
Value for specified position:
  __getitem__(self, i)
Value for specified position.
int __len__(self)
Get length: supports len( this )
0|1 __eq__(self, o)
Comparison equal: supports this == other
0|1 __ne__(self, o)
Comparison not equal: supports this != other
SparseArray __getslice__(self, a, b)
Slice a sparce array:
0|1 __contains__(self, v)
Sparse array contains value: supports v in this -> 0|1
int count(self, v)
Count the occuravces of value in sparse array:
int index(self, v)
position of first occurrence of value:
1|0 empty(self)
Check if object is empty.
  __delitem__(self, i)
Delete value at index i: supports del this[i]
  insert(self, i, v)
Insert value before index:
  append(self, v, axis=0)
Enlarge this array along an axis by one value:
  extend(self, lst)
Extend list by appending elements from the iterable:

Method Details [hide private]

__init__(self, array_or_shape=0, typecode='f', default=0.)
(Constructor)

source code 

Create a sparse array from a normal Numeric array or create an empty sparse array with a certain shape.
Parameters:
  • array_or_shape (( int, ) OR int OR array) - craeate sparse array from:
                            ( int, ),   shape of array
                             OR int,     length of array
                             OR array,   numeric (dense) array
    
  • typecode (str) - single char type of values ['f' OR input type]
  • default (any) - value of majority of array content (default: 0.)

__setAll_1D(self, a)

source code 

Replace content of this sparseArray with values from Numeric array or list of numbers -- only for 1-dimensional arrays.
Parameters:
  • a (array OR [ number ]) - array OR list

__setAll(self, a)

source code 

Replace content of this array with values from (multidimensional) Numeric array of numbers or list of lists (of lists..) of numbers.
Parameters:
  • a (array OR [ [ number ] ]) - array OR list of lists

typecode(self)

source code 

Get type code of object.
Returns: str
typecode of lowest dimension

default(self)

source code 

Get default value, defined in __init__.
Returns: number
default value for array elements (of lowest dimension)

nondefault(self)

source code 

Get a 1D list of indices that have a non-default value in a raveled version of this array. If L.default()==0 this would be equivalent to nonzero( ravel( L.toarray() ) ) (except that the Numeric array is never constructed).
Returns: [ int ]
list of indices with none default values

nondefault_values(self)

source code 

Get a 1D-list of all values != L.default() in the order that they would have in a raveled array. If L.default()==0 this would be equivalent to take( L.toarray(), nonzero( ravel( L.toarray() ) ) ) (except that the Numeric array is never constructed).
Returns: [ number ]
list of none default values

toarray(self)

source code 

Reconstruct dense array:
 L.toarray() -> Numeric.array, normal dense array
Returns: array
normal dense array

tolist(self)

source code 

Reconstruct list from dense array:
 L.tolist() -> [ ([) number (]) ], same as L.toarray().tolist()
Returns: list
list from normal dense array

put(self, i, v)

source code 

Replace one or several values, L.put( i, v )
Parameters:
  • i (int OR [ int ]) - indices
  • v (any OR [ any ]) - values

__setMany(self, indices, values)

source code 

Add / replace values of the array.
Parameters:
  • indices ([int]) - indices, [ int ] OR Numeric.array('i')
  • values ([any] OR array) - values, [ any ] OR Numeric.array

__pos(self, i)

source code 

Target position of given index in index list.
Parameters:
  • i (int) - index
Returns: int
target position of given index in index list
Raises:
  • IndexError - if out of bounds

__setitem__(self, i, v)
(Index assignment operator)

source code 

Set position specifyed by the index i to value v.
Parameters:
  • i (int OR (int,int)) - index
  • v (any) - value
Raises:

__setitem_1D(self, i, v)

source code 

Set position specifyed by the index i to value v in a 1D array.
Parameters:
  • i (int) - array index
  • v (any) - value
Raises:
  • IndexError - if i < 0 or i > len( this )

__getitem_1D(self, i)

source code 

Value for specified position:
 this[ i ] -> number OR SparseArray
Parameters:
  • i (int) - array index
Raises:
  • IndexError - if i < 0 or i >= len( this )

__getitem__(self, i)
(Indexing operator)

source code 

Value for specified position.
Parameters:
  • i (int OR (int,int)) - array index

__len__(self)
(Length operator)

source code 

Get length: supports len( this )
Returns: int
object length

__eq__(self, o)
(Equality operator)

source code 

Comparison equal: supports this == other
Returns: 0|1
result of comparison

__ne__(self, o)

source code 

Comparison not equal: supports this != other
Returns: 0|1
result of comparison

__getslice__(self, a, b)
(Slicling operator)

source code 

Slice a sparce array:
 this[ a : b ] -> SparseArray
Returns: SparseArray
sliced sparse array

__contains__(self, v)
(In operator)

source code 

Sparse array contains value: supports v in this -> 0|1
Parameters:
  • v (any) - value
Returns: 0|1
result of comparison

count(self, v)

source code 

Count the occuravces of value in sparse array:
 count( value ) -> int, number of occurences of value.
Parameters:
  • v (any) - value
Returns: int
number of occurances

index(self, v)

source code 

position of first occurrence of value:
 index( value ) -> int
Parameters:
  • v (any) - value to look for
Returns: int
index of first occurance
Raises:
  • ValueError - if value is not contained in this list

empty(self)

source code 

Check if object is empty.
Returns: 1|0
true if lenght is 0

__delitem__(self, i)
(Index deletion operator)

source code 

Delete value at index i: supports del this[i]
Parameters:
  • i (int) - index

Note: del this[int:int] is not supported

insert(self, i, v)

source code 

Insert value before index:
 this.insert(index, value) 
Parameters:
  • v (any) - value to insert
  • i (int) - index
Raises:
  • IndexError - if i < 0 or i > len( this )

append(self, v, axis=0)

source code 

Enlarge this array along an axis by one value:
 L.append( value, [ axis=0 ])
Parameters:
  • v (number OR SparseArray) - v MUST be a sparse array if the given axis is not the last axis of this array
  • axis (int) - dimension along wich v should be added
Raises:

extend(self, lst)

source code 

Extend list by appending elements from the iterable:
 L.extend(iterable)
Parameters:
  • lst ([any] OR SparseArray) - list OR SparseArray with extend values