Use scipy.stats.ttest_ind(a, b) to test whether two independent samples have different means. SciPy’s default, equal_var=True, assumes equal population variances; set equal_var=False for Welch’s test when you do not want that assumption. Before interpreting the p-value, confirm that the groups are independent, choose the alternative hypothesis, and decide how missing values should be handled.
Choose the test to match the study design
ttest_ind is for two independent samples: observations in one group are not paired or repeated measurements of the same units as observations in the other. If measurements are matched or repeated, this is not the appropriate substitute for a paired test.
As an Amazon Associate I earn from qualifying purchases.
For independent groups, choose the variance assumption deliberately. The default pooled test assumes equal population variances. Welch’s test does not make that assumption and is requested with equal_var=False. Do not choose between them based on which produces a more favorable p-value; match the method to the design and analysis plan.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →| Choice | Setting or condition | What it means |
|---|---|---|
| Equal-variance independent-samples test | equal_var=True (default) |
Assumes the two populations have equal variances. |
| Welch’s independent-samples test | equal_var=False |
Does not assume equal population variances. |
| Directional hypothesis | alternative='less' or 'greater' |
Tests the direction of the difference in the order the samples are passed. |
| Trimmed Yuen test | Nonzero trim |
Uses trimmed observations and winsorized means in the variance calculation; choose it when justified by the distribution, not as automatic outlier deletion. |
| Resampling p-value | method set to a PermutationMethod or MonteCarloMethod instance |
Uses a configured resampling procedure instead of the default theoretical t-distribution calculation. |
Call ttest_ind in Python
The SciPy v1.18.0 API reference consulted on October 7, 2026, gives this signature: SciPy ttest_ind API reference.
#1 Best Overall
from scipy import stats
result = stats.ttest_ind(group_a, group_b, equal_var=False)
print(result.statistic, result.pvalue, result.df)
This example requests Welch’s test. Use it when that variance assumption fits your analysis; it is not a way to make a result significant. The default alternative is two-sided. The current signature is:
scipy.stats.ttest_ind(
a, b, *, axis=0, equal_var=True, nan_policy='propagate',
alternative='two-sided', trim=0, method=None, keepdims=False
)
Understand the input shape
The inputs can be array-like. By default, SciPy calculates along axis=0, so the arrays must have matching shapes except along the tested axis. Set axis=None to flatten the inputs before calculating. With batched inputs, the test is computed for each slice along the selected axis.
Rank #2
Choose the alternative in the input order
alternative='two-sided' tests for a difference in either direction. 'less' tests whether the mean underlying the first sample is less than the second; 'greater' tests whether it is greater. These directional alternatives refer to a then b. Reversing the inputs reverses the directional interpretation and the sign of the statistic. Set a directional alternative only when it matches the hypothesis chosen for the analysis.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Handle missing values explicitly
The default, nan_policy='propagate', returns NaN for an affected axis slice. Choose another policy only if it reflects your data-handling plan:
'omit'excludes NaNs from the calculation and returns NaN if too little data remains. The comparison then uses only the observations left after omission.'raise'raisesValueErrorif a NaN occurs in a slice.
Interpret the statistic and p-value
The statistic is the difference between the sample means, mean(a) - mean(b), divided by its standard error. A positive value means the first sample mean is larger; a negative value means it is smaller. The result includes the statistic, p-value, and degrees of freedom for the standard calculation.
The p-value describes how compatible the observed result is with the selected null hypothesis and alternative under the test procedure. It is not the probability that the null hypothesis is true, and it does not measure whether the difference matters in practice. Report the group summaries and an effect estimate or confidence interval where appropriate. The result object documents a confidence-interval method for supported calculations; consult the documentation for your installed SciPy version for its exact behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Use trimming or resampling only when justified
Trimmed Yuen test
A nonzero trim requests a trimmed Yuen test. SciPy describes trimming a fraction of observations from each tail and using winsorized means for the variance calculation. Its API reference recommends trimming when the underlying distribution is long-tailed or contaminated with outliers. This changes the analysis; it is not an automatic command to delete outliers.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minutePermutation and Monte Carlo methods
By default, SciPy calculates the p-value using a theoretical t-distribution. The current API accepts a PermutationMethod or MonteCarloMethod instance through method to configure resampling. Resampling may be computationally expensive, and SciPy cautions that permutation testing is not necessarily more accurate than the analytical test. Older examples using permutations or random_state do not reflect the current documented resampling interface.
Best Value
Check version-specific behavior
The API details above follow SciPy v1.18.0 documentation accessed October 7, 2026. That reference describes method as the resampling interface and labels Python Array API support experimental. Backend and device compatibility can vary; check the live API reference before relying on a particular backend.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




