• Python: 3.8.11
  • Numpy: 1.20.1
  • OS: Ubuntu Kylin 20.04
  • Conda: 4.10.1
  • Jupyter lab: 3.1.4

Code sample

import numpy as np
Copy the code
Create an array with 3 rows and 2 columns
a = np.zeros([3.2])
a

array([[0..0.],
       [0..0.],
       [0..0.]])
Copy the code
Change the value of an element in the array
a[0.0] = 2.1
a

array([[2.1.0. ],
       [0. , 0. ],
       [0. , 0. ]])
Copy the code
# Out-of-index access, IndexError
a[2.3]

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-13-b23c88c532a1> in <module>
      1 # Out-of-index access, IndexError
----> 2 a[2.3]

IndexError: index 3 is out of bounds for axis 1 with size 2
Copy the code

The source code to learn

help(np.zeros)

Help on built-in function zeros in module numpy:

zeros(...)
    zeros(shape, dtype=float, order='C', *, like=None)
    
    Return a new array of given shape and type, filled with zeros.

......
Copy the code

Learning to recommend

  • Python documentation – English
  • Python documentation – Chinese
  • Python code PEP
  • Google version of the Python specification
  • Python source code
  • Python PEP
  • Optimal kirin
  • The nuggets platform
  • Gitee platform


Python is open source, cross-platform, interpretive, interactive, and worth learning. Python’s design philosophy: elegant, unambiguous, simple. Advocate one way, preferably only one way to do one thing. Code should be written in accordance with specifications to facilitate communication and understanding. Every language has its own unique ideas. Beginners need to change their thinking, practice and accumulate.