Skip to content

Commit 5920f6c

Browse files
Bartosz Telenczukbtel
authored andcommitted
add alternative solution to exercise 64
1 parent e35f345 commit 5920f6c

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

100 Numpy exercises.ipynb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"source": [
77
"# 100 numpy exercises\n",
88
"\n",
9-
"This is a collection of exercises that have been collected in the numpy mailing list, on stack overflow and in the numpy documentation. I've also created some to reach the 100 limit. The goal of this collection is to offer a quick reference for both old and new users but also to provide a set of exercices for those who teach.\n",
9+
"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 exercices for those who teach.\n",
1010
"\n",
1111
"\n",
12-
"If you find an error or think you've a better way to solve some of them, feel free top open an issue at <https://github.com/rougier/numpy-100>"
12+
"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>"
1313
]
1414
},
1515
{
@@ -1359,6 +1359,11 @@
13591359
"Z = np.ones(10)\n",
13601360
"I = np.random.randint(0,len(Z),20)\n",
13611361
"Z += np.bincount(I, minlength=len(Z))\n",
1362+
"print(Z)\n",
1363+
"\n",
1364+
"# Another solution\n",
1365+
"# Author: Bartosz Telenczuk\n",
1366+
"np.add.at(Z, I, 1)\n",
13621367
"print(Z)"
13631368
]
13641369
},

100 Numpy exercises.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11

22
# 100 numpy exercises
33

4-
This is a collection of exercises that have been collected in the numpy mailing
5-
list, on stack overflow and in the numpy documentation. I've also created some
6-
to reach the 100 limit. The goal of this collection is to offer a quick
7-
reference for both old and new users but also to provide a set of exercices for
8-
those who teach.
4+
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 exercices for those who teach.
95

10-
If you find an error or think you've a better way to solve some of them, feel
11-
free to open an issue at <https://github.com/rougier/numpy-100>
6+
7+
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>
128

139
#### 1. Import the numpy package under the name `np` (★☆☆)
1410

@@ -43,7 +39,10 @@ print("%d bytes" % (Z.size * Z.itemsize))
4339

4440
#### 5. How to get the documentation of the numpy add function from the command line? (★☆☆)
4541

46-
$ `python -c "import numpy; numpy.info(numpy.add)"`
42+
43+
```python
44+
%run `python -c "import numpy; numpy.info(numpy.add)"`
45+
```
4746

4847
#### 6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)
4948

@@ -651,6 +650,11 @@ Z = np.ones(10)
651650
I = np.random.randint(0,len(Z),20)
652651
Z += np.bincount(I, minlength=len(Z))
653652
print(Z)
653+
654+
# Another solution
655+
# Author: Bartosz Telenczuk
656+
np.add.at(Z, I, 1)
657+
print(Z)
654658
```
655659

656660
#### 65. How to accumulate elements of a vector (X) to an array (F) based on an index list (I)? (★★★)

0 commit comments

Comments
 (0)