LoginSignup
2
1

More than 5 years have passed since last update.

The sample of numpy.percentile and how to index the larger array than original array

Posted at
print("====percentile====")
X = np.random.randn(1) # random 1D array
N = 10 # number of bootstrap samples
print(X.size)
idx = np.random.randint(0, X.size, (N, X.size))
print("====means====")
print(X)
print(idx)
print(X[idx])
print(X.shape, idx.shape, X[idx].shape)
means = X[idx].mean(axis=1)
print(means.shape)
confint = np.percentile(means, [2.5, 97.5])
print(confint)
  • e.g.
====percentile====
1
====means====
[ 0.41599196]
[[0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]]
[[ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]
 [ 0.41599196]]
((1,), (10, 1), (10, 1))
(10,)
[0.41599196248944836, 0.41599196248944836]

Refs.

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1