Args:
            names (tuple[str]): the names ('train' or 'test') of the datasets

        Returns:
            An array of three values as mean of each channel, for all images in the given datasets.
768312
def get_per_channel_mean(self, names=('train', 'test')):
        
        mean = self.get_per_pixel_mean(names)
        return np.mean(mean, axis=(0, 1))
213983
def load_dataset(data_name):
    """"""
    if data_name == 'MR' or data_name == 'Subj':
        train_dataset, output_size = _load_file(data_name)
        vocab, max_len = _build_vocab(data_name, train_dataset, [])
        train_dataset, train_data_lengths = _preprocess_dataset(train_dataset, vocab, max_len)
        return vocab, max_len, output_size, train_dataset, train_data_lengths
    else:
        train_dataset, test_dataset, output_size = _load_file(data_name)
        vocab, max_len = _build_vocab(data_name, train_dataset, test_dataset)
        train_dataset, train_data_lengths = _preprocess_dataset(train_dataset, vocab, max_len)
        test_dataset, test_data_lengths = _preprocess_dataset(test_dataset, vocab, max_len)
        return vocab, max_len, output_size, train_dataset, train_data_lengths, test_dataset, \
               test_data_lengths
195270
private static MeanMagnitudes getLayerMeanMagnitudes(int layerIdx, TrainModuleUtils.GraphInfo gi,
                    List<Persistable> updates, List<Integer> iterationCounts, ModelType modelType) {
        if (gi == null) {
            return new MeanMagnitudes(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap(),
                            Collections.emptyMap());
        }

        String layerName = gi.getVertexNames().get(layerIdx);
        if (modelType != ModelType.CG) {
            //Get the original name, for the index...
            layerName = gi.getOriginalVertexName().get(layerIdx);
        }
        String layerType = gi.getVertexTypes().get(layerIdx);
        if ("input".equalsIgnoreCase(layerType)) { //TODO better checking - other vertices, etc
            return new MeanMagnitudes(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap(),
                            Collections.emptyMap());
        }

        List<Integer> iterCounts = new ArrayList<>();
        Map<String, List<Double>> ratioValues = new HashMap<>();
        Map<String, List<Double>> outParamMM = new HashMap<>();
        Map<String, List<Double>> outUpdateMM = new HashMap<>();

        if (updates != null) {
            int pCount = -1;
            for (Persistable u : updates) {
                pCount++;
                if (!(u instanceof StatsReport))
                    continue;
                StatsReport sp = (StatsReport) u;
                if (iterationCounts != null) {
                    iterCounts.add(iterationCounts.get(pCount));
                } else {
                    int iterCount = sp.getIterationCount();
                    iterCounts.add(iterCount);
                }


                //Info we want, for each parameter in this layer: mean magnitudes for parameters, updates AND the ratio of these
                Map<String, Double> paramMM = sp.getMeanMagnitudes(StatsType.Parameters);
                Map<String, Double> updateMM = sp.getMeanMagnitudes(StatsType.Updates);
                for (String s : paramMM.keySet()) {
                    String prefix;
                    if (modelType == ModelType.Layer) {
                        prefix = layerName;
                    } else {
                        prefix = layerName + "_";
                    }

                    if (s.startsWith(prefix)) {
                        //Relevant parameter for this layer...
                        String layerParam = s.substring(prefix.length());
                        double pmm = paramMM.getOrDefault(s, 0.0);
                        double umm = updateMM.getOrDefault(s, 0.0);
                        if (!Double.isFinite(pmm)) {
                            pmm = NAN_REPLACEMENT_VALUE;
                        }
                        if (!Double.isFinite(umm)) {
                            umm = NAN_REPLACEMENT_VALUE;
                        }
                        double ratio;
                        if (umm == 0.0 && pmm == 0.0) {
                            ratio = 0.0; //To avoid NaN from 0/0
                        } else {
                            ratio = umm / pmm;
                        }
                        List<Double> list = ratioValues.get(layerParam);
                        if (list == null) {
                            list = new ArrayList<>();
                            ratioValues.put(layerParam, list);
                        }
                        list.add(ratio);

                        List<Double> pmmList = outParamMM.get(layerParam);
                        if (pmmList == null) {
                            pmmList = new ArrayList<>();
                            outParamMM.put(layerParam, pmmList);
                        }
                        pmmList.add(pmm);

                        List<Double> ummList = outUpdateMM.get(layerParam);
                        if (ummList == null) {
                            ummList = new ArrayList<>();
                            outUpdateMM.put(layerParam, ummList);
                        }
                        ummList.add(umm);
                    }
                }
            }
        }

        return new MeanMagnitudes(iterCounts, ratioValues, outParamMM, outUpdateMM);
    }
95798
def filter_samples(names, seqs, sep='.'):
    
    seen = set()
    filtered_names, filtered_seqs = [], []
    for name, seq in zip(names, seqs):
        samp = name.split(sep, 1)[0]
        if samp in seen:
            continue
        seen.add(samp)
        filtered_names.append(name)
        filtered_seqs.append(seq)

    nfiltered, nnames = len(filtered_names), len(names)
    assert nfiltered == len(seen)

    return filtered_names, filtered_seqs, seen
514070
def GlobalAvgPooling(x, data_format='channels_last'):
    
    assert x.shape.ndims == 4
    data_format = get_data_format(data_format)
    axis = [1, 2] if data_format == 'channels_last' else [2, 3]
    return tf.reduce_mean(x, axis, name='output')
1087681
def show_channel_names(self):
        
        for name in self.get_channel_names():
            channel = self.get_channel(name)
            channel.fitsimage.onscreen_message(name, delay=2.5)
812111
def get_tensors_by_names(names):
    
    ret = []
    G = tfv1.get_default_graph()
    for n in names:
        opn, varn = get_op_tensor_name(n)
        ret.append(G.get_tensor_by_name(varn))
    return ret
941177
def target_names(targets):
    """"""
    names = []
    for entry in targets:
        if isinstance(entry, ast.Name):
            names.append(entry.id)
        elif isinstance(entry, ast.Tuple):
            for element in entry.elts:
                if isinstance(element, ast.Name):
                    names.append(element.id)

    return names
1014540
def iter_variants_by_names(self, names):
        
        if not self.is_parallel:
            yield from super().iter_variants_by_names(names)

        else:
            for info, dosage in self._bgen.iter_variants_by_names(names):
                yield Genotypes(
                    Variant(info.name,
                            CHROM_STR_ENCODE.get(info.chrom, info.chrom),
                            info.pos, [info.a1, info.a2]),
                    dosage,
                    reference=info.a1,
                    coded=info.a2,
                    multiallelic=True,
                )
1169575
def list_names():
    
    names = get_all_names()
    # This is 375 right now. Probably won't ever change, but I'm not sure.
    nameslen = len(names)
    print('\nListing {} names:\n'.format(nameslen))
    # Using 3 columns of names, still alphabetically sorted from the top down.
    # Longest name so far: lightgoldenrodyellow (20 chars)
    namewidth = 20
    # namewidth * columns == 60, colorwidth * columns == 18, final == 78.
    swatch = ' ' * 9

    third = nameslen // 3
    lastthird = third * 2
    cols = (
        names[0: third],
        names[third: lastthird],
        names[lastthird:],
    )
    # Exactly enough spaces to fill in a blank item (+2 for ': ').
    # This may not ever be used, unless another 'known name' is added.
    blankitem = ' ' * (namewidth + len(swatch) + 2)

    for i in range(third):
        nameset = []
        for colset in cols:
            try:
                nameset.append(colset[i])
            except IndexError:
                nameset.append(None)
                continue
        line = C('').join(
            C(': ').join(
                C(name.rjust(namewidth)),
                C(swatch, back=name),
            ) if name else blankitem
            for name in nameset
        )
        print(line)

    return 0
840826
def get_data_iters(dataset, batch_size, opt):
    """"""
    if dataset == 'mnist':
        train_data, val_data = get_mnist_iterator(batch_size, (1, 28, 28),
                                                  num_parts=kv.num_workers, part_index=kv.rank)
    elif dataset == 'cifar10':
        train_data, val_data = get_cifar10_iterator(batch_size, (3, 32, 32),
                                                    num_parts=kv.num_workers, part_index=kv.rank)
    elif dataset == 'imagenet':
        shape_dim = 299 if model_name == 'inceptionv3' else 224

        if not opt.data_dir:
            raise ValueError('Dir containing raw images in train/val is required for imagenet.'
                             'Please specify "--data-dir"')

        train_data, val_data = get_imagenet_iterator(opt.data_dir, batch_size,
                                                                opt.num_workers, shape_dim, opt.dtype)
    elif dataset == 'caltech101':
        train_data, val_data = get_caltech101_iterator(batch_size, opt.num_workers, opt.dtype)
    elif dataset == 'dummy':
        shape_dim = 299 if model_name == 'inceptionv3' else 224
        train_data, val_data = dummy_iterator(batch_size, (3, shape_dim, shape_dim))
    return train_data, val_data
1061726
def results(self, names=None, alpha=_alpha, mode='peak', **kwargs):
        
        if names is None: names = self.names
        ret = odict()
        for n in names:
            ret[n] = getattr(self,'%s_interval'%mode)(n, **kwargs)
        return ret
499207
def output_connections(self, name):
        
        for output_name in self._compound_children[name].outputs:
            src = name, output_name
            if src in self._compound_linkages:
                dests = self._compound_linkages[src]
                if isinstance(dests[0], six.string_types):
                    dests = zip(dests[0::2], dests[1::2])
                for dest in dests:
                    yield src, dest
547370
def calc_shape_statistics(self, stat_names):
        
        stats = {}
        try:
            all_props = [regionprops(m) for m in self.masks]
        except TypeError:
            print(self.masks)
            exit()
        for stat in stat_names:
            stats[stat] = np.mean([p[0][stat] for p in all_props])
        return stats
246098
def get_all_names(self):
        """"""
        result = set()
        for module in self.names:
            result.update(set(self.names[module]))
        return result
561607
def iterate_similarity_datasets(args):
    
    for dataset_name in args.similarity_datasets:
        parameters = nlp.data.list_datasets(dataset_name)
        for key_values in itertools.product(*parameters.values()):
            kwargs = dict(zip(parameters.keys(), key_values))
            yield dataset_name, kwargs, nlp.data.create(dataset_name, **kwargs)
1170406
def set_entry_points(self, names):
        
        names = util.return_set(names)
        self.entry_point_names = names