Created
June 6, 2018 07:01
-
-
Save hiramekun/8da9977d51535fde322f36534712d613 to your computer and use it in GitHub Desktop.
配列生成方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup(): | |
np.random.seed(100) | |
x = np.zeros(1000) | |
u = np.random.rand(1000) | |
flag = (u >= 0) & (u < 1/8) | |
x[flag] = np.sqrt(8 * u[flag]) | |
flag = (u >= 1/8) & (u < 1/4) | |
x[flag] = 2 - np.sqrt(2 - 8 * u[flag]) | |
flag = (u >= 1/4) & (u < 1/2) | |
x[flag] = 1 + 4 * u[flag] | |
flag = (u >= 1/2) & (u < 3/4) | |
x[flag] = 3 + np.sqrt(4 * u[flag] - 2) | |
flag = (u >= 3/4) & (u <= 1) | |
x[flag] = 5 - np.sqrt(4 - 4 * u[flag]) | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
flag = (u >= 0) & (u < 1/8)
で範囲指定x[flag] = np.sqrt(8 * u[flag])
でその範囲内の数値のみ変更