Notebook: Line magic function not found

Created on 10 Dec 2019  路  2Comments  路  Source: jupyter/notebook

Input in Kaggle Jupyter Notebook:

import numpy as np
from numpy.random import randint

# A function to simulate one million dice throws.
def one_million_dice():
    return randint(low=1, high=7, size=100000)

# Let's try %time first
%time throws = one_million_dice()
%time mean = np.mean(throws)

# Outputs:
# Wall time: 20.6 ms
# Wall time: 3.01 ms

# Let's do the same with %timeit
%timeit throws = one_million_dice()
%timeit mean = np.mean(throws)

# Outputs:
# 10 loops, best of 3: 22.2 ms per loop
# 100 loops, best of 3: 2.86 ms per loop

# And finally %%time
%%time
throws = one_million_dice()
mean = np.mean(throws)

# Outputs:
# Wall time: 36.6 ms

Output:

CPU times: user 4 ms, sys: 0 ns, total: 4 ms
Wall time: 1.55 ms
CPU times: user 0 ns, sys: 0 ns, total: 0 ns
Wall time: 495 碌s
1.06 ms 卤 1.62 碌s per loop (mean 卤 std. dev. of 7 runs, 1000 loops each)
102 碌s 卤 741 ns per loop (mean 卤 std. dev. of 7 runs, 10000 loops each)
UsageError: Line magic function `%%time` not found.

image

Most helpful comment

I think that you want to put each magic section in its own cell. So any line that starts with % should be the beginning of a new input cell.

All 2 comments

I think that you want to put each magic section in its own cell. So any line that starts with % should be the beginning of a new input cell.

I think that you want to put each magic section in its own cell. So any line that starts with % should be the beginning of a new input cell.

thanks锛宨t really helps. magic function should be put in single code cell.

Was this page helpful?
0 / 5 - 0 ratings