Compare commits
10 Commits
8366787686
...
4b759efce8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b759efce8 | ||
|
|
a4ac12cdc6 | ||
|
|
683f473a6f | ||
|
|
dc425d7872 | ||
|
|
9182fdc110 | ||
|
|
e83ba5f309 | ||
|
|
9357b79e1d | ||
|
|
fccab23c7e | ||
|
|
4c45b35878 | ||
|
|
ed48a838ce |
File diff suppressed because it is too large
Load Diff
@@ -3,15 +3,12 @@
|
||||
|
||||
# 100 numpy exercises
|
||||
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack
|
||||
overflow
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack overflow
|
||||
and in the numpy documentation. The goal of this collection is to offer a quick reference for both old
|
||||
and new
|
||||
users but also to provide a set of exercises for those who teach.
|
||||
and new users but also to provide a set of exercises for those who teach.
|
||||
|
||||
|
||||
If you find an error or think you've a better way to
|
||||
solve some of them, feel
|
||||
If you find an error or think you've a better way to solve some of them, feel
|
||||
free to open an issue at <https://github.com/rougier/numpy-100>.
|
||||
File automatically generated. See the documentation to update questions/answers/hints programmatically.
|
||||
|
||||
@@ -221,7 +218,7 @@ np.sqrt(-1) == np.emath.sqrt(-1)
|
||||
|
||||
#### 85. Create a 2D array subclass such that Z[i,j] == Z[j,i] (★★★)
|
||||
|
||||
#### 86. Consider a set of p matrices wich shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
#### 86. Consider a set of p matrices with shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
|
||||
#### 87. Consider a 16x16 array, how to get the block-sum (block size is 4x4)? (★★★)
|
||||
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
|
||||
# 100 numpy exercises
|
||||
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack
|
||||
overflow
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack overflow
|
||||
and in the numpy documentation. The goal of this collection is to offer a quick reference for both old
|
||||
and new
|
||||
users but also to provide a set of exercises for those who teach.
|
||||
and new users but also to provide a set of exercises for those who teach.
|
||||
|
||||
|
||||
If you find an error or think you've a better way to
|
||||
solve some of them, feel
|
||||
If you find an error or think you've a better way to solve some of them, feel
|
||||
free to open an issue at <https://github.com/rougier/numpy-100>.
|
||||
File automatically generated. See the documentation to update questions/answers/hints programmatically.
|
||||
|
||||
@@ -221,7 +218,7 @@ np.sqrt(-1) == np.emath.sqrt(-1)
|
||||
`hint: stride_tricks.as_strided, from numpy.lib.stride_tricks import sliding_window_view (np>=1.20.0)`
|
||||
#### 85. Create a 2D array subclass such that Z[i,j] == Z[j,i] (★★★)
|
||||
`hint: class method`
|
||||
#### 86. Consider a set of p matrices wich shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
#### 86. Consider a set of p matrices with shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
`hint: np.tensordot`
|
||||
#### 87. Consider a 16x16 array, how to get the block-sum (block size is 4x4)? (★★★)
|
||||
`hint: np.add.reduceat, from numpy.lib.stride_tricks import sliding_window_view (np>=1.20.0)`
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
|
||||
# 100 numpy exercises
|
||||
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack
|
||||
overflow
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack overflow
|
||||
and in the numpy documentation. The goal of this collection is to offer a quick reference for both old
|
||||
and new
|
||||
users but also to provide a set of exercises for those who teach.
|
||||
and new users but also to provide a set of exercises for those who teach.
|
||||
|
||||
|
||||
If you find an error or think you've a better way to
|
||||
solve some of them, feel
|
||||
If you find an error or think you've a better way to solve some of them, feel
|
||||
free to open an issue at <https://github.com/rougier/numpy-100>.
|
||||
File automatically generated. See the documentation to update questions/answers/hints programmatically.
|
||||
|
||||
@@ -615,8 +612,17 @@ print(Z[Z[:,1].argsort()])
|
||||
```python
|
||||
# Author: Warren Weckesser
|
||||
|
||||
# null : 0
|
||||
Z = np.random.randint(0,3,(3,10))
|
||||
print((~Z.any(axis=0)).any())
|
||||
|
||||
# null : np.nan
|
||||
Z=np.array([
|
||||
[0,1,np.nan],
|
||||
[1,2,np.nan],
|
||||
[4,5,np.nan]
|
||||
])
|
||||
print(np.isnan(Z).all(axis=0))
|
||||
```
|
||||
#### 61. Find the nearest value from a given value in an array (★★☆)
|
||||
`hint: np.abs, argmin, flat`
|
||||
@@ -648,7 +654,7 @@ class NamedArray(np.ndarray):
|
||||
return obj
|
||||
def __array_finalize__(self, obj):
|
||||
if obj is None: return
|
||||
self.info = getattr(obj, 'name', "no name")
|
||||
self.name = getattr(obj, 'name', "no name")
|
||||
|
||||
Z = NamedArray(np.arange(10), "range_10")
|
||||
print (Z.name)
|
||||
@@ -998,7 +1004,7 @@ S = symetric(np.random.randint(0,10,(5,5)))
|
||||
S[2,3] = 42
|
||||
print(S)
|
||||
```
|
||||
#### 86. Consider a set of p matrices wich shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
#### 86. Consider a set of p matrices with shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
`hint: np.tensordot`
|
||||
|
||||
```python
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
|
||||
# 100 numpy exercises
|
||||
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack
|
||||
overflow
|
||||
This is a collection of exercises that have been collected in the numpy mailing list, on stack overflow
|
||||
and in the numpy documentation. The goal of this collection is to offer a quick reference for both old
|
||||
and new
|
||||
users but also to provide a set of exercises for those who teach.
|
||||
and new users but also to provide a set of exercises for those who teach.
|
||||
|
||||
|
||||
If you find an error or think you've a better way to
|
||||
solve some of them, feel
|
||||
If you find an error or think you've a better way to solve some of them, feel
|
||||
free to open an issue at <https://github.com/rougier/numpy-100>.
|
||||
File automatically generated. See the documentation to update questions/answers/hints programmatically.
|
||||
|
||||
@@ -615,8 +612,17 @@ print(Z[Z[:,1].argsort()])
|
||||
```python
|
||||
# Author: Warren Weckesser
|
||||
|
||||
# null : 0
|
||||
Z = np.random.randint(0,3,(3,10))
|
||||
print((~Z.any(axis=0)).any())
|
||||
|
||||
# null : np.nan
|
||||
Z=np.array([
|
||||
[0,1,np.nan],
|
||||
[1,2,np.nan],
|
||||
[4,5,np.nan]
|
||||
])
|
||||
print(np.isnan(Z).all(axis=0))
|
||||
```
|
||||
#### 61. Find the nearest value from a given value in an array (★★☆)
|
||||
|
||||
@@ -648,7 +654,7 @@ class NamedArray(np.ndarray):
|
||||
return obj
|
||||
def __array_finalize__(self, obj):
|
||||
if obj is None: return
|
||||
self.info = getattr(obj, 'name', "no name")
|
||||
self.name = getattr(obj, 'name', "no name")
|
||||
|
||||
Z = NamedArray(np.arange(10), "range_10")
|
||||
print (Z.name)
|
||||
@@ -998,7 +1004,7 @@ S = symetric(np.random.randint(0,10,(5,5)))
|
||||
S[2,3] = 42
|
||||
print(S)
|
||||
```
|
||||
#### 86. Consider a set of p matrices wich shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
#### 86. Consider a set of p matrices with shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
|
||||
|
||||
```python
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a194d42e",
|
||||
"id": "e06c1964",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 100 numpy exercises\n",
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a7fd49f7",
|
||||
"id": "c108c1c4",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"File automatically generated. See the documentation to update questions/answers/hints programmatically."
|
||||
@@ -26,7 +26,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b702d5a2",
|
||||
"id": "2aefe09b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Run the `initialize.py` module, then call a random question with `pick()` an hint towards its solution with\n",
|
||||
@@ -36,7 +36,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "da60e1d0",
|
||||
"id": "55c8f855",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -46,7 +46,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9fb544fe",
|
||||
"id": "8f1e8a4a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
@@ -19,5 +19,4 @@ This work is licensed under the MIT license.
|
||||
|
||||
### Variants in Other Languages
|
||||
|
||||
#### Julia
|
||||
- [100 Julia Exercises](https://github.com/RoyiAvital/Julia100Exercises).
|
||||
- **Julia**: [100 Julia Exercises](https://github.com/RoyiAvital/Julia100Exercises).
|
||||
|
||||
@@ -108,7 +108,7 @@ def create_markdown(destination_filename='100_Numpy_exercises', with_hints=False
|
||||
|
||||
# Add questions (and hint or answers if required)
|
||||
for n in range(1, 101):
|
||||
mdfile.new_header(title=f"{n}. {QHA[f'q{n}']}", level=4)
|
||||
mdfile.new_header(title=f"{n}. {QHA[f'q{n}']}", level=4, add_table_of_contents="n")
|
||||
if with_hints:
|
||||
mdfile.write(f"`{QHA[f'h{n}']}`")
|
||||
if with_solutions:
|
||||
|
||||
@@ -1246,7 +1246,7 @@ S[2,3] = 42
|
||||
print(S)
|
||||
|
||||
< q86
|
||||
Consider a set of p matrices wich shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
Consider a set of p matrices with shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)
|
||||
|
||||
< h86
|
||||
hint: np.tensordot
|
||||
|
||||
Reference in New Issue
Block a user