A dict of arrays that stores data and annotation.

        It is sufficient for reconstructing the object.
352596
def _to_dict_fixed_width_arrays(self, var_len_str=True):
        
        self.strings_to_categoricals()
        obs_rec, uns_obs = df_to_records_fixed_width(self._obs, var_len_str)
        var_rec, uns_var = df_to_records_fixed_width(self._var, var_len_str)
        layers = self.layers.as_dict()
        d = {
            'X': self._X,
            'obs': obs_rec,
            'var': var_rec,
            'obsm': self._obsm,
            'varm': self._varm,
            'layers': layers,
            # add the categories to the unstructured annotation
            'uns': {**self._uns, **uns_obs, **uns_var}}

        if self.raw is not None:
            self.strings_to_categoricals(self.raw._var)
            var_rec, uns_var = df_to_records_fixed_width(self.raw._var, var_len_str)
            d['raw.X'] = self.raw.X
            d['raw.var'] = var_rec
            d['raw.varm'] = self.raw.varm
            d['raw.cat'] = uns_var

        return d
194215
def serialize(self):
        

        data = {}
        for k, v in self.iteritems():
            if k.startswith('_'):
                continue

            if isinstance(v, APIModel):
                data[k] = v.serialize()
            elif v and is_seq_not_string(v) and isinstance(v[0], APIModel):
                data[k] = [x.serialize() for x in v]
            else:
                data[k] = v

        return data
806576
def prepare(self, data):
        
        result = {}

        if not self.fields:
            # No fields specified. Serialize everything.
            return data

        for fieldname, lookup in self.fields.items():
            if isinstance(lookup, SubPreparer):
                result[fieldname] = lookup.prepare(data)
            else:
                result[fieldname] = self.lookup_data(lookup, data)

        return result
1278053
def dict(self):
        
        collection = super().dict()
        serialized_items = []
        for item in collection['items']:
            serialized_items.append(self.serializer(item))

        collection['items'] = serialized_items
        return collection
1346298
def data_object(self):
        
        data_obj = []

        for i in range(0, len(self.data)):
            obj = {
                'value': self.data[i],
                'label': self.labels[i],
                'color': self.colors[i],
            }
            data_obj.append(obj)
        return data_obj
273242
def load_to_array(self, keys):
        
        # Preallocate the numpy array
        data = np.empty((len(self.data[keys[0]]), len(keys)))
        for i in range(0, len(self.data[keys[0]])):
            for j, key in enumerate(keys):
                data[i, j] = self.data[key][i]
        return data
506021
def decode_numpy_dict_values(attrs: Mapping[K, V]) -> Dict[K, V]:
    
    attrs = dict(attrs)
    for k, v in attrs.items():
        if isinstance(v, np.ndarray):
            attrs[k] = v.tolist()
        elif isinstance(v, np.generic):
            attrs[k] = v.item()
    return attrs
1351431
def create_dictionary_representation
      dict = { storyboards: [],
               table_cells: [],
               collection_cells: [],
               view_controllers: [],
               segues: [],
               prefix: @config.prefix }

      @project.resources.each do |group|
        dict[:storyboards] << group.storyboard
        dict[:table_cells] += group.table_cells
        dict[:collection_cells] += group.collection_cells
        dict[:view_controllers] += group.view_controllers
        dict[:segues] += group.segues
      end

      # Build up flags.
      dict[:has_table_cells] = (dict[:table_cells].count > 0)
      dict[:has_collection_cells] = (dict[:collection_cells].count > 0)
      dict[:has_segues] = (dict[:segues].count > 0)

      dict
    end
464999
def read_array(self, key, start=None, stop=None):
        
        import tables
        node = getattr(self.group, key)
        attrs = node._v_attrs

        transposed = getattr(attrs, 'transposed', False)

        if isinstance(node, tables.VLArray):
            ret = node[0][start:stop]
        else:
            dtype = getattr(attrs, 'value_type', None)
            shape = getattr(attrs, 'shape', None)

            if shape is not None:
                # length 0 axis
                ret = np.empty(shape, dtype=dtype)
            else:
                ret = node[start:stop]

            if dtype == 'datetime64':

                # reconstruct a timezone if indicated
                ret = _set_tz(ret, getattr(attrs, 'tz', None), coerce=True)

            elif dtype == 'timedelta64':
                ret = np.asarray(ret, dtype='m8[ns]')

        if transposed:
            return ret.T
        else:
            return ret
218028
def as_struct_array(*columns):
    
    columns = [np.asarray(c) for c in columns]
    rows = len(columns[0])

    names = ['f'+str(i) for i in range(len(columns))]
    dtype = [(names[i], c.dtype, c.shape[1:]) for i, c in enumerate(columns)]
    data = np.empty(rows, dtype)
    for i, c in enumerate(columns):
        data[names[i]] = c
    return data
1262084
def to_serializable_dict(self, attrs_to_serialize=None,
                             rels_to_expand=None,
                             rels_to_serialize=None,
                             key_modifications=None):
        
        return self.todict(
            attrs_to_serialize=attrs_to_serialize,
            rels_to_expand=rels_to_expand, rels_to_serialize=rels_to_serialize,
            key_modifications=key_modifications)
1292559
def JSON_NumpyArrayEncoder(obj):
    ''''''
    if isinstance(obj, np.ndarray):
        return {'numpyArray': obj.tolist(),
                'dtype': obj.dtype.__str__()}
    elif isinstance(obj, np.generic):
        return np.asscalar(obj)
    else:
        print type(obj)
        raise TypeError(repr(obj) + " is not JSON serializable")
43733
def serialize_ndarray_readable(o):
    
    return dict(
        _type='np.ndarray',
        dtype=o.dtype,
        value=hint_tuples(o.tolist()))
383863
def dict(self):
        
        from collections import OrderedDict

        d = OrderedDict(
            [(p.key, getattr(self, p.key)) for p in self.__mapper__.attrs if p.key not in ('data',)])

        if 'list' in self.data:
            d['bundle_count'] = len(self.data['list'])
        else:
            d['bundle_count'] = None

        if self.data:
            for k, v in self.data.items():
                d[k] = v

        return d
91962
def store_vector(self, hash_name, bucket_key, v, data):
        
        mongo_key = self._format_mongo_key(hash_name, bucket_key)

        val_dict = {}
        val_dict['lsh'] = mongo_key

        # Depending on type (sparse or not) fill value dict
        if scipy.sparse.issparse(v):
            # Make sure that we are using COO format (easy to handle)
            if not scipy.sparse.isspmatrix_coo(v):
                v = scipy.sparse.coo_matrix(v)

            # Construct list of [index, value] items,
            # one for each non-zero element of the sparse vector
            encoded_values = []

            for k in range(v.data.size):
                row_index = v.row[k]
                value = v.data[k]
                encoded_values.append([int(row_index), value])

            val_dict['sparse'] = 1
            val_dict['nonzeros'] = encoded_values
            val_dict['dim'] = v.shape[0]
        else:
            # Make sure it is a 1d vector
            v = numpy.reshape(v, v.shape[0])
            val_dict['vector'] = v.tostring()

        val_dict['dtype'] = v.dtype.name

        # Add data if set
        if data is not None:
            val_dict['data'] = data

        # Push JSON representation of dict to end of bucket list
        self.mongo_object.insert_one(val_dict)
105250
def serialize(d):
    
    ret = {}
    for k,v in d.items():
        if not k.startswith('_'):
            ret[k] = str(d[k])
    #ret['__class__'] = obj.__class__.__name__
    return ret
115320
def _store(
    results,
    key_name,
    array,
    n_splits,
    n_candidates,
    weights=None,
    splits=False,
    rank=False,
):
    """"""
    # When iterated first by n_splits and then by parameters
    array = np.array(array, dtype=np.float64).reshape(n_splits, n_candidates).T
    if splits:
        for split_i in range(n_splits):
            results["split%d_%s" % (split_i, key_name)] = array[:, split_i]

    array_means = np.average(array, axis=1, weights=weights)
    results["mean_%s" % key_name] = array_means
    # Weighted std is not directly available in numpy
    array_stds = np.sqrt(
        np.average((array - array_means[:, np.newaxis]) ** 2, axis=1, weights=weights)
    )
    results["std_%s" % key_name] = array_stds

    if rank:
        results["rank_%s" % key_name] = np.asarray(
            rankdata(-array_means, method="min"), dtype=np.int32
        )