У меня есть код, который выглядит так:
Код: Выделить всё
import numpy as np
from scipy.stats import mannwhitneyu
from tqdm import tqdm
# Basics
runs = 10000
scores = 100000
states = 1000
# Random scores
score = np.random.rand(runs * scores).reshape(runs, scores)
score.shape
# Random states
state = np.random.choice(
[True, False],
p=[0.01, 0.99], # Roughly 1% True, 99% False (on average)
size=scores * states,
).reshape(states, scores)
state.shape
muh_ps = np.zeros((runs, states))
for i in tqdm(range(runs), desc="Runs", total=runs):
sc = score[i]
for st in tqdm(range(states), desc="States", total=states):
rp = sc[state[st]]
rn = sc[~state[st]]
u_statistic, u_pvalue = mannwhitneyu(rp, rn, alternative="two-sided")
muh_ps[i, st] = u_pvalue
print(muh_ps)
Большое спасибо за подсказки/предложения по оптимизации и извините за вопрос для начинающих.
Я попробовал «наивный» подход, показанный выше, и ожидал, что он будет «медленным». .. на самом деле неплохо:
Код: Выделить всё
test_man.py
States: 100%|███████████████████████████████████████| 1000/1000 [00:38
Подробнее здесь: [url]https://stackoverflow.com/questions/78979759/optimisation-suggestions-for-mann-whitney-u-test-in-scipy[/url]