def encoded_to_array(encoded):
    """
    Turn a dictionary with base64 encoded strings back into a numpy array.

    Parameters
    ------------
    encoded : dict
      Has keys:
        dtype: string of dtype
        shape: int tuple of shape
        base64: base64 encoded string of flat array
        binary:  decode result coming from numpy.tostring

    Returns
    ----------
    array: numpy array
    """

    if not isinstance(encoded, dict):
        if is_sequence(encoded):
            as_array = np.asanyarray(encoded)
            return as_array
        else:
            raise ValueError('Unable to extract numpy array from input')

    encoded = decode_keys(encoded)

    dtype = np.dtype(encoded['dtype'])
    if 'base64' in encoded:
        array = np.frombuffer(base64.b64decode(encoded['base64']),
                              dtype)
    elif 'binary' in encoded:
        array = np.frombuffer(encoded['binary'],
                              dtype=dtype)
    if 'shape' in encoded:
        array = array.reshape(encoded['shape'])
    return array
def encoded_to_array ( encoded ) : if not isinstance ( encoded , dict ) : if is_sequence ( encoded ) : as_array = np . asanyarray ( encoded ) return as_array else : raise ValueError ( 'Unable to extract numpy array from input' ) encoded = decode_keys ( encoded ) dtype = np . dtype ( encoded [ 'dtype' ] ) if 'base64' in encoded : array = np . frombuffer ( base64 . b64decode ( encoded [ 'base64' ] ) , dtype ) elif 'binary' in encoded : array = np . frombuffer ( encoded [ 'binary' ] , dtype = dtype ) if 'shape' in encoded : array = array . reshape ( encoded [ 'shape' ] ) return array
Turn a dictionary with base64 encoded strings back into a numpy array.

    Parameters
    ------------
    encoded : dict
      Has keys:
        dtype: string of dtype
        shape: int tuple of shape
        base64: base64 encoded string of flat array
        binary:  decode result coming from numpy.tostring

    Returns
    ----------
    array: numpy array