teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

補足を追加

2017/07/28 04:34

投稿

magichan
magichan

スコア15898

answer CHANGED
@@ -3,4 +3,27 @@
3
3
  https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html](https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html)
4
4
  ```python
5
5
  ds = np.histogram(xp/dx, bins=np.arange(nx+1))[0]
6
- ```
6
+ ```
7
+
8
+ ---
9
+
10
+ **【補足】**
11
+
12
+ コメントにて依頼があったので、他の方法を何点か
13
+
14
+ ```Python
15
+ ds =np.zeros(nx)
16
+ for i in np.arange(nx):
17
+ d = xp/dx
18
+ ds[i] = ((i <= d) & (d < i+1)).sum()
19
+ ```
20
+
21
+ ```Python
22
+ ds =np.zeros(nx)
23
+ for i in np.arange(nx):
24
+ ds[i] = ((xp/dx).astype(int) == i).sum()
25
+ ```
26
+
27
+ ```Python
28
+ ds = np.bincount((xp/dx).astype(int))
29
+ ```