10 examples of 'bins in histogram python' in Python

Every line of 'bins in histogram python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
3def bin(X, binsize = 1):
4 """Split X into bins and return the average of each bin as a new set of
5 measurements."""
6 if binsize == 1:
7 return X;
8 else:
9 extra = 0 if pl.size(X, axis = 0) % binsize == 0 else 1
10 dims = [i for i in pl.shape(X)]
11 dims[0] = dims[0] / binsize + extra
12 dims = tuple(dims)
13 X_binned = pl.zeros(dims)
14
15 for i in xrange(pl.size(X_binned, axis = 0)):
16 X_binned[i] = pl.mean(X[i * binsize:(i + 1) * binsize], axis = 0)
17
18 return X_binned
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

160def bin(X, nbins=20):
161 equa0 = (X <= 0.0)
162 equa1 = (X >= 1.0)
163
164 binned = []
165
166 groups = range(nbins+1)
167 for g1, g2 in zip(groups, groups[1:]):
168 l, u = g1/float(nbins), g2/float(nbins)
169 binned.append((l < X) & (X <= u))
170 retval = np.concatenate([equa0, equa1] + binned, axis=1)
171 return retval
9def py_histogram(int_vec):
10
11 hist = {}
12 for val in int_vec:
13 hist[val] = 1 + hist.get(val, 0)
14
15 return hist
4def histogramValues(values):
5 counts, binEdges = histogram(values, bins=40, density=True)
6 ys = list(counts)
7 xs = []
8 for i in range(len(binEdges) - 1):
9 xs.append((binEdges[i] + binEdges[i + 1]) / 2)
10 return xs, ys
107def bins(self):
108 raise NotImplementedError("bins is not implemented")
48def plot_histogram(values, num_bins=100):
49 """
50 Generates a plot of the histograms of grasps by probability of force closure
51 """
52 bin_edges = np.linspace(np.min(values), np.max(values), num_bins+1)
53 plt.figure()
54 n, bins, patches = plt.hist(values, bin_edges)
23def calculate_histogram(data, bins: int, signal: str):
24 stats = data.statistics['signals'][signal]
25 maximum, minimum = stats['max']['value'], stats['min']['value']
26 width = 3.5 * np.sqrt(stats['σ2']['value']) / (data.sample_count ** (1. / 3))
27 num_bins = bins if bins > 0 else ceil((maximum - minimum) / width)
28 hist = None
29 bin_edges = None
30
31 for data_chunk in data:
32 if bin_edges is None:
33 hist, bin_edges = np.histogram(data_chunk['signals'][signal]['value'],
34 range=(minimum, maximum), bins=num_bins)
35 else:
36 hist += np.histogram(data_chunk['signals'][signal]['value'], bins=bin_edges)[0]
37
38 return hist, bin_edges
127def fast_hist(a, b, n):
128 k = (a >= 0) & (a < n)
129 return np.bincount(n * a[k].astype(int) + b[k], minlength=n**2).reshape(n, n)
84def hist(data, title='histogram', bins=10, **args):
85 histFig = pyecharts.charts.Bar()
86 histFig.set_global_opts(title_opts=opts.TitleOpts(title=title))
87 y, x = np.histogram(data, bins=bins)
88 x = x.astype(int).astype(str)
89 xlabels = [x[i - 1] + '-' + x[i] for i in range(1, len(x))]
90 histFig.add_xaxis(xlabels)
91 histFig.add_yaxis(data.name, y.tolist(), **args)
92 result = histFig.render_notebook(
93 ) if Config['return_type'] == 'HTML' else histFig
94 return result
154def _histogram(image,
155 min,
156 max,
157 bins):
158 """
159 Delayed wrapping of NumPy's histogram
160
161 Also reformats the arguments.
162 """
163
164 return numpy.histogram(image, bins, (min, max))[0]

Related snippets