diff --git a/README.md b/README.md index 828ba2a..f2b4084 100644 --- a/README.md +++ b/README.md @@ -2267,7 +2267,8 @@ log.basicConfig( * **Parent logger can be specified by naming the child logger `'.'`.** * **If logger doesn't have a set level it inherits it from the first ancestor that does.** * **Formatter also accepts: pathname, filename, funcName, lineno, thread and process.** -* **A `'log.handlers.RotatingFileHandler'` creates and deletes log files based on 'maxBytes' and 'backupCount' arguments.** +* **RotatingFileHandler creates and deletes files based on 'maxBytes' and 'backupCount' args.** +* **An object with `'filter()'` method (or the method itself) can be added to loggers and handlers via addFilter(). Message is dropped if filter() returns a false value.** #### Creates a logger that writes all messages to file and sends them to the root's handler that prints warnings or higher: ```python @@ -2306,8 +2307,7 @@ delattr(, '') # Same. Also `del .`. = inspect.signature() # Returns function's Signature object. = .parameters # Dict of Parameters. Also .return_annotation. = .kind # Member of ParamKind enum (Parameter.KEYWORD_ONLY, …). - = .default # Returns parameter's default value or Parameter.empty. - = .annotation # Returns parameter's type hint or Parameter.empty. + = .default # Parameter.empty if missing. Also .annotation. ``` @@ -2707,32 +2707,33 @@ import numpy as np ``` * **`':'` returns a slice of all dimension's indices. Omitted dimensions default to `':'`.** * **Indices should not be tuples because Python converts `'obj[i, j]'` to `'obj[(i, j)]'`!** -* **`'ix_()'` returns two 2d arrays. Indices of different shapes get unified with broadcasting.** +* **Indexing with a slice and 1d array works the same as when using two slices (lines 4, 6, 7).** +* **`'ix_([1, 2], [3, 4])'` returns `'[[1], [2]]'` and `'[[3, 4]]'`. Due to broadcasting rules, this is the same as using `'[[1, 1], [2, 2]]'` and `'[[3, 4], [3, 4]]'`.** * **Any value that is broadcastable to the indexed shape can be assigned to the selection.** ### Broadcasting **Set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.** ```python -left = [[0.1], [0.6], [0.8]] # Shape: (3, 1) -right = [ 0.1 , 0.6 , 0.8 ] # Shape: (3,) +left = [ 0.1 , 0.6 , 0.8 ] # Shape: (3,) +right = [[0.1], [0.6], [0.8]] # Shape: (3, 1) ``` #### 1. If array shapes differ in length, left-pad the shorter shape with ones: ```python -left = [[0.1], [0.6], [0.8]] # Shape: (3, 1) -right = [[0.1 , 0.6 , 0.8]] # Shape: (1, 3) <- ! +left = [[0.1 , 0.6 , 0.8]] # Shape: (1, 3) <- ! +right = [[0.1], [0.6], [0.8]] # Shape: (3, 1) ``` #### 2. If any dimensions differ in size, expand the ones that have size 1 by duplicating their elements: ```python -left = [[0.1, 0.1, 0.1], # Shape: (3, 3) <- ! - [0.6, 0.6, 0.6], - [0.8, 0.8, 0.8]] - -right = [[0.1, 0.6, 0.8], # Shape: (3, 3) <- ! +left = [[0.1, 0.6, 0.8], # Shape: (3, 3) <- ! [0.1, 0.6, 0.8], [0.1, 0.6, 0.8]] + +right = [[0.1, 0.1, 0.1], # Shape: (3, 3) <- ! + [0.6, 0.6, 0.6], + [0.8, 0.8, 0.8]] ``` ### Example @@ -2740,15 +2741,13 @@ right = [[0.1, 0.6, 0.8], # Shape: (3, 3) <- ! ```python >>> points = np.array([0.1, 0.6, 0.8]) - [ 0.1, 0.6, 0.8] +[ 0.1, 0.6, 0.8 ] >>> wrapped_points = points.reshape(3, 1) -[[ 0.1], - [ 0.6], - [ 0.8]] ->>> distances = wrapped_points - points -[[ 0. , -0.5, -0.7], - [ 0.5, 0. , -0.2], - [ 0.7, 0.2, 0. ]] +[[0.1], [0.6], [0.8]] +>>> distances = points - wrapped_points +[[ 0. , 0.5, 0.7], + [-0.5, 0. , 0.2], + [-0.7, -0.2, 0. ]] >>> distances = np.abs(distances) [[ 0. , 0.5, 0.7], [ 0.5, 0. , 0.2], diff --git a/index.html b/index.html index fc37809..eb06d2d 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1863,7 +1863,8 @@ log.debug/info/warning/error/critical(<str>) '<parent>.<name>'.
  • If logger doesn't have a set level it inherits it from the first ancestor that does.
  • Formatter also accepts: pathname, filename, funcName, lineno, thread and process.
  • -
  • A 'log.handlers.RotatingFileHandler' creates and deletes log files based on 'maxBytes' and 'backupCount' arguments.
  • +
  • RotatingFileHandler creates and deletes files based on 'maxBytes' and 'backupCount' args.
  • +
  • An object with 'filter(<LogRecord>)' method (or the method itself) can be added to loggers and handlers via addFilter(). Message is dropped if filter() returns a false value.
  • Creates a logger that writes all messages to file and sends them to the root's handler that prints warnings or higher:

    >>> logger = log.getLogger('my_module')
     >>> handler = log.FileHandler('test.log', encoding='utf-8')
    @@ -1875,7 +1876,7 @@ log.debug/info/warning/error/critical(<str>)      >>> logger.critical('Running out of disk space.')
     CRITICAL:my_module:Running out of disk space.
     >>> print(open('test.log').read())
    -2023-02-07 23:21:01,430 CRITICAL:my_module:Running out of disk space.
    +2023-02-07 23:21:01,430 CRITICAL:my_module:Running out of disk space.
     

    #Introspection

    <list> = dir()                          # Names of local vars, functions, classes and modules.
    @@ -1893,8 +1894,7 @@ delattr(<obj>, '<attr_name>')
     
    <Sig>  = inspect.signature(<function>)  # Returns function's Signature object.
     <dict> = <Sig>.parameters               # Dict of Parameters. Also <Sig>.return_annotation.
     <memb> = <Param>.kind                   # Member of ParamKind enum (Parameter.KEYWORD_ONLY, …).
    -<obj>  = <Param>.default                # Returns parameter's default value or Parameter.empty.
    -<type> = <Param>.annotation             # Returns parameter's type hint or Parameter.empty.
    +<obj>  = <Param>.default                # Parameter.empty if missing. Also <Param>.annotation.
     

    #Coroutines

    • Coroutines have a lot in common with threads, but unlike threads, they only give up control when they call another coroutine and they don’t use as much memory.
    • @@ -2215,37 +2215,36 @@ $ snakeviz test.prof ':'
      returns a slice of all dimension's indices. Omitted dimensions default to ':'.
    • Indices should not be tuples because Python converts 'obj[i, j]' to 'obj[(i, j)]'!
    • -
    • 'ix_()' returns two 2d arrays. Indices of different shapes get unified with broadcasting.
    • +
    • Indexing with a slice and 1d array works the same as when using two slices (lines 4, 6, 7).
    • +
    • 'ix_([1, 2], [3, 4])' returns '[[1], [2]]' and '[[3, 4]]'. Due to broadcasting rules, this is the same as using '[[1, 1], [2, 2]]' and '[[3, 4], [3, 4]]'.
    • Any value that is broadcastable to the indexed shape can be assigned to the selection.
    -

    Broadcasting

    Set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.

    left  = [[0.1], [0.6], [0.8]]                           # Shape: (3, 1)
    -right = [ 0.1 ,  0.6 ,  0.8 ]                           # Shape: (3,)
    +

    Broadcasting

    Set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.

    left  = [ 0.1 ,  0.6 ,  0.8 ]                           # Shape: (3,)
    +right = [[0.1], [0.6], [0.8]]                           # Shape: (3, 1)
     
    -

    1. If array shapes differ in length, left-pad the shorter shape with ones:

    left  = [[0.1], [0.6], [0.8]]                           # Shape: (3, 1)
    -right = [[0.1 ,  0.6 ,  0.8]]                           # Shape: (1, 3) <- !
    +

    1. If array shapes differ in length, left-pad the shorter shape with ones:

    left  = [[0.1 ,  0.6 ,  0.8]]                           # Shape: (1, 3) <- !
    +right = [[0.1], [0.6], [0.8]]                           # Shape: (3, 1)
     
    -

    2. If any dimensions differ in size, expand the ones that have size 1 by duplicating their elements:

    left  = [[0.1,  0.1,  0.1],                             # Shape: (3, 3) <- !
    -         [0.6,  0.6,  0.6],
    -         [0.8,  0.8,  0.8]]
    -
    -right = [[0.1,  0.6,  0.8],                             # Shape: (3, 3) <- !
    +

    2. If any dimensions differ in size, expand the ones that have size 1 by duplicating their elements:

    left  = [[0.1,  0.6,  0.8],                             # Shape: (3, 3) <- !
              [0.1,  0.6,  0.8],
              [0.1,  0.6,  0.8]]
    +
    +right = [[0.1,  0.1,  0.1],                             # Shape: (3, 3) <- !
    +         [0.6,  0.6,  0.6],
    +         [0.8,  0.8,  0.8]]
     

    Example

    For each point returns index of its nearest point ([0.1, 0.6, 0.8] => [1, 2, 1]):

    >>> points = np.array([0.1, 0.6, 0.8])
    - [ 0.1,  0.6,  0.8]
    +[ 0.1,  0.6,  0.8 ]
     >>> wrapped_points = points.reshape(3, 1)
    -[[ 0.1],
    - [ 0.6],
    - [ 0.8]]
    ->>> distances = wrapped_points - points
    -[[ 0. , -0.5, -0.7],
    - [ 0.5,  0. , -0.2],
    - [ 0.7,  0.2,  0. ]]
    +[[0.1], [0.6], [0.8]]
    +>>> distances = points - wrapped_points
    +[[ 0. ,  0.5,  0.7],
    + [-0.5,  0. ,  0.2],
    + [-0.7, -0.2,  0. ]]
     >>> distances = np.abs(distances)
     [[ 0. ,  0.5,  0.7],
      [ 0.5,  0. ,  0.2],
    @@ -2933,7 +2932,7 @@ $ deactivate                  # Deactivates the activ
      
     
       
    - +
    diff --git a/parse.js b/parse.js index 619bab0..af0bb1b 100755 --- a/parse.js +++ b/parse.js @@ -208,13 +208,13 @@ const PROGRESS_BAR = 'Processing: 100%|████████████████████| 3/3 [00:03<00:00, 1.00s/it]\n'; const LOGGING_EXAMPLE = - '>>> logger = logging.getLogger(\'my_module\')\n' + - '>>> handler = logging.FileHandler(\'test.log\', encoding=\'utf-8\')\n' + - '>>> handler.setFormatter(logging.Formatter(\'%(asctime)s %(levelname)s:%(name)s:%(message)s\'))\n' + + '>>> logger = log.getLogger(\'my_module\')\n' + + '>>> handler = log.FileHandler(\'test.log\', encoding=\'utf-8\')\n' + + '>>> handler.setFormatter(log.Formatter(\'%(asctime)s %(levelname)s:%(name)s:%(message)s\'))\n' + '>>> logger.addHandler(handler)\n' + '>>> logger.setLevel(\'DEBUG\')\n' + - '>>> logging.basicConfig()\n' + - '>>> logging.root.handlers[0].setLevel(\'WARNING\')\n' + + '>>> log.basicConfig()\n' + + '>>> log.root.handlers[0].setLevel(\'WARNING\')\n' + '>>> logger.critical(\'Running out of disk space.\')\n' + 'CRITICAL:my_module:Running out of disk space.\n' + '>>> print(open(\'test.log\').read())\n' + @@ -838,7 +838,7 @@ function fixHighlights() { $(`code:contains(import asyncio, collections, curses, curses.textpad, enum, random)`).html(COROUTINES); $(`code:contains(import curses, os)`).html(CURSES); $(`code:contains(pip3 install tqdm)`).html(PROGRESS_BAR); - $(`code:contains(>>> logging.basicConfig()`).html(LOGGING_EXAMPLE); + $(`code:contains(>>> log.basicConfig()`).html(LOGGING_EXAMPLE); $(`code:contains(samples_f = (sin(i *)`).html(AUDIO); $(`code:contains(collections, dataclasses, enum, io, itertools)`).html(MARIO); $(`code:contains(>>> gb = df.groupby)`).html(GROUPBY);