Skip to content

Commit 24d6cdd

Browse files
committed
Fix some typos and make some sentences clearer
1 parent 275c25d commit 24d6cdd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

content/numpy.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ Exercises 4
325325

326326
- **In-place addition** (advanced): Create an array of
327327
``dtype='float'``, and an array of ``dtype='int'``. Try to use the
328-
int array is the output argument of the first two arrays.
328+
int array as the output argument of the first two arrays.
329329

330330
- **Output arguments and timing** Repeat the initial ``b = a **
331-
2`` example using the output arguments and time it. Can you make
331+
2`` example using a ufunc and time it. Can you make
332332
it even faster using the output argument?
333333

334334
.. solution:: Solution: Numpy-4
@@ -337,22 +337,21 @@ Exercises 4
337337

338338
x = np.array([1, 2, 3])
339339
id(x) # get the memory-ID of x
340-
np.add(x, x, x) # Third argument is output array
341-
np.add(x, x, x)
340+
np.add(x, x, out=x) # Third argument is output array
341+
np.add(x, x, out=x)
342342
print(x)
343343
id(x) # get the memory-ID of x
344344
# - notice it is the same
345345

346-
You note that ``np.add()`` has a third argument that is the
347-
output array (same as ``out=``), *and* the function returns that
348-
same array.
346+
Note that ``np.add()`` writes the result to the output array (``out=``)
347+
*and* the function returns that same array.
349348

350349

351350
- **Output arguments and timing** In this case, on my computer, it was
352351
actually slower (this is due to it being such a small array!)::
353352

354-
a = np.arange(10000)
355-
b = np.zeros(10000)
353+
a = np.arange(10_000)
354+
b = np.zeros(10_000)
356355

357356
::
358357

@@ -362,6 +361,11 @@ Exercises 4
362361
This is a good example of why you always need to time things
363362
before deciding what is best.
364363

364+
Note: the ``_`` inside numbers is just for human readability and is
365+
ignored by python.
366+
367+
368+
365369

366370
Linear algebra and other advanced math
367371
--------------------------------------

0 commit comments

Comments
 (0)