code: def array_to_encoded(array, dtype=None, encoding='base64'):
      
      array = np.asanyarray(array)
      shape = array.shape
      # ravel also forces contiguous
      flat = np.ravel(array)
      if dtype is None:
          dtype = array.dtype
  
      encoded = {'dtype': np.dtype(dtype).str,
                 'shape': shape}
      if encoding in ['base64', 'dict64']:
          packed = base64.b64encode(flat.astype(dtype).tostring())
          if hasattr(packed, 'decode'):
              packed = packed.decode('utf-8')
          encoded['base64'] = packed
      elif encoding == 'binary':
          encoded['binary'] = array.tostring(order='C')
      else:
          raise ValueError('encoding {} is not available!'.format(encoding))
      return encoded
docs: Export a numpy array to a compact serializable dictionary.
  
      Parameters
      ------------
      array : array
        Any numpy array
      dtype : str or None
        Optional dtype to encode array
      encoding : str
        'base64' or 'binary'
  
      Returns
      ---------
      encoded : dict
        Has keys:
        'dtype':  str, of dtype
        'shape':  tuple of shape
        'base64': str, base64 encoded string