bw2calc.indexing#
Functions#
|
Map |
|
Build a dictionary from the sorted, unique elements of an array, and map this dictionary from |
Module Contents#
- bw2calc.indexing.index_with_arrays(array_from, array_to, mapping)[source]#
Map
array_fromkeys toarray_tovalues using the dictionarymapping.Turns the keys and values of mapping into index arrays.
This is needed to take the
flow,input, andoutputcolumns, which can be arbitrarily large integers, and transform them to matrix indices, which start from zero.Here is an example:
import numpy as np a_f = np.array((1, 2, 3, 4)) a_t = np.zeros(4) mapping = {1: 5, 2: 6, 3: 7, 4: 8} index_with_arrays(a_f, a_t, mapping) # => a_t is now [5, 6, 7, 8]
- Parameters:
array_from (*) – 1-dimensional integer numpy array.
array_to (*) – 1-dimensional integer numpy array.
mapping (*) – Dictionary that links
mappingindices toroworcolindices, e.g.{34: 3}.
Operates in place. Doesn’t return anything.
- bw2calc.indexing.index_with_searchsorted(array_from, array_to)[source]#
Build a dictionary from the sorted, unique elements of an array, and map this dictionary from
array_fromtoarray_to.Adapted from http://stackoverflow.com/questions/3403973/fast-replacement-of-values-in-a-numpy-array.
Here is an example:
import numpy as np array = np.array((4, 8, 6, 2, 4)) output = np.zeros(5) index_with_searchsorted(array, output) # => returns {2: 0, 4: 1, 6: 2, 8: 3} # and `output` is [1, 3, 2, 0, 1]
array_fromandarray_toare arrays of integers.Returns a dictionary that maps the sorted, unique elements of
array_fromto integers starting with zero.