Compare commits

...

10 Commits

Author SHA1 Message Date
Nicolas P. Rougier
4b759efce8 Regenerate all the files 2023-04-03 09:26:02 +02:00
Nicolas P. Rougier
a4ac12cdc6 Merge pull request #196 from jeremy-feng/master
Fixed a typo
2023-04-03 09:24:11 +02:00
jeremy-feng
683f473a6f Fixed a typo 2023-03-18 15:20:15 +08:00
Nicolas P. Rougier
dc425d7872 Merge pull request #190 from Stefan-Heimersheim/master
Remove incorrect alternative solution q19
2022-12-05 18:41:02 +01:00
Stefan Heimersheim
9182fdc110 Remove incorrect alternative solution q19
The reshape-based solution for q19 did only work for odd numbered squares, not even ones such as 8x8 squares.
2022-11-29 14:29:35 +00:00
Nicolas P. Rougier
e83ba5f309 Fixed generators (see https://github.com/didix21/mdutils/issues/69) 2022-10-17 13:43:14 +02:00
Nicolas P. Rougier
9357b79e1d Merge pull request #189 from HenryJi529/master
Add alternative solution for Q.19
2022-10-17 13:38:53 +02:00
Henry Ji
fccab23c7e Add alternative solution for Q.19 2022-10-10 20:58:25 +08:00
Nicolas P. Rougier
4c45b35878 Merge pull request #177 from RoyiAvital/patch-1
Update README.md
2022-04-10 12:51:45 +02:00
Royi
ed48a838ce Update README.md 2022-04-09 23:37:19 +03:00
9 changed files with 249 additions and 244 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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)? (★★★)

View File

@@ -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)`

View File

@@ -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

View File

@@ -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

View File

@@ -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": [

View File

@@ -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).

View File

@@ -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:

View File

@@ -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