Python NumPy Module Cheatsheet: Unterschied zwischen den Versionen

Aus MattWiki
K Matt verschob die Seite Python Numpy nach Python NumPy Module Cheatsheet, ohne dabei eine Weiterleitung anzulegen
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
== NumPy Module ==
```python
import numpy as np
```
== NumPy Array ==
```python
my_list = [92, 94, 88, 91, 87]
numpy_array_from_list = np.array(my_list)
``
== NumPy Array from CSV File ==
```python
csv_file_name = 'test_2.csv'
numpy_array_from_csv_file = np.genfromtxt(csv_file_name, delimiter=',')
``
== Operations on NumPy Arrays ==
numpy_array = np.array([1, 2, 3, 4, 5])
print(numpy_array + 1)
returns [2, 3, 4, 5, 6]
print(numpy_array ** 2)
returns [1, 2, 9, 16, 25]
== Variance ==
== Variance ==
<syntaxhighlight lang="python3">import numpy as np
<syntaxhighlight lang="python3">import numpy as np

Version vom 28. Februar 2025, 09:28 Uhr

NumPy Module

```python import numpy as np ```

NumPy Array

```python my_list = [92, 94, 88, 91, 87] numpy_array_from_list = np.array(my_list) ``

NumPy Array from CSV File

```python csv_file_name = 'test_2.csv' numpy_array_from_csv_file = np.genfromtxt(csv_file_name, delimiter=',') ``

Operations on NumPy Arrays

numpy_array = np.array([1, 2, 3, 4, 5])
print(numpy_array + 1)
returns [2, 3, 4, 5, 6]
print(numpy_array ** 2)
returns [1, 2, 9, 16, 25]


Variance

import numpy as np

dividends_microsoft_eur = [0.6358, 0.6308, 0.6364, 0.6854, 0.6876, 0.7016, 0.7016, 0.7906]
variance_dividends_microsoft = np.var(dividends_microsoft_eur)

print('The variance of Microsoft stock dividends in 2023 and 2024 is', variance_dividends_microsoft)

Standard Deviation