You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/numpy/concepts/built-in-functions/terms/mean/mean.md
+21-26Lines changed: 21 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -214,29 +214,24 @@ for i, avg in enumerate(exam_averages, 1):
214
214
print(f"\nOverall class average: {class_average:.1f}")
215
215
```
216
216
217
-
## FAQs
218
-
219
-
<details>
220
-
<summary>1. What's the difference between `np.mean()` and `np.average()`?</summary>
221
-
<p>While both calculate the arithmetic mean, `np.average()` allows specifying weights for elements, enabling weighted averages, whereas `np.mean()` treats all values equally.</p>
222
-
</details>
223
-
224
-
<details>
225
-
<summary>2. How does NumPy's `.mean()` handle `NaN` values?</summary>
226
-
<p>By default, `.mean()` will return `NaN` if any of the values being averaged are `NaN`. To ignore `NaN` values, use `np.nanmean()` instead.</p>
227
-
</details>
228
-
229
-
<details>
230
-
<summary>3. Can `.mean()` calculate the mean of strings or other non-numeric data?</summary>
231
-
<p>No, `.mean()` works only with numeric data. Attempting to calculate the mean of non-numeric data will result in a `TypeError`.</p>
232
-
</details>
233
-
234
-
<details>
235
-
<summary>4. How can dimensions be preserved when calculating means along an axis?</summary>
236
-
<p>Set the `keepdims=True` parameter to maintain the dimensions of the original array in the output.</p>
237
-
</details>
238
-
239
-
<details>
240
-
<summary>5. Is there a performance difference between using `.mean()` method and the `np.mean()` function?</summary>
241
-
<p>No significant performance difference exists between `arr.mean()` and `np.mean(arr)` as they both call the same underlying implementation. Choose the syntax that makes code more readable.</p>
242
-
</details>
217
+
## Frequently Asked Questions
218
+
219
+
### 1. What's the difference between `np.mean()` and `np.average()`?
220
+
221
+
While both calculate the arithmetic mean, `np.average()` allows specifying weights for elements, enabling weighted averages, whereas `np.mean()` treats all values equally.
222
+
223
+
### 2. How does NumPy's `.mean()` handle `NaN` values?
224
+
225
+
By default, `.mean()` will return `NaN` if any of the values being averaged are `NaN`. To ignore `NaN` values, use `np.nanmean()` instead.
226
+
227
+
### 3. Can `.mean()` calculate the mean of strings or other non-numeric data?
228
+
229
+
No, `.mean()` works only with numeric data. Attempting to calculate the mean of non-numeric data will result in a `TypeError`.
230
+
231
+
### 4. How can dimensions be preserved when calculating means along an axis?
232
+
233
+
Set the `keepdims=True` parameter to maintain the dimensions of the original array in the output.
234
+
235
+
### 5. Is there a performance difference between using `.mean()` method and the `np.mean()` function?
236
+
237
+
No significant performance difference exists between `arr.mean()` and `np.mean(arr)` as they both call the same underlying implementation. Choose the syntax that makes code more readable.
0 commit comments