程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Creating arrays in Python: numpy Empty() and numpy Zeros() and numpy Ones() and numpy full()

編輯:Python

NumPy Create array

  • numpy.empty
    • 1. usage :
    • 2. Parameters :
    • 3. example :
  • numpy.zeros
    • 1. usage :
    • 2. Parameters :
    • 3. example :
  • numpy.ones
    • 1. usage :
    • 2. Parameters :
    • 3. example :
  • numpy.full
    • 1. usage :
    • 2. Parameters :
    • 3. example :

numpy.empty

1. usage :

This method is used to create a specified dimension (shape)、 data type (dtype) Uninitialized array of .

numpy.empty(shape, dtype=float, order='C')

2. Parameters :

  • shape: A tuple representing an array dimension
  • dtype: data type
  • order: Yes “C” and “F” Two options

3. example :


Create an empty array ( Subsequently, users are required to manually set all values in the array ):

empty() Methods and zeros() The method is different , The array value will not be set to zero , So it could be a little faster . On the other hand , It requires the user to manually set all values in the array , And use it with caution .

numpy.zeros

1. usage :

Create the specified dimension , With 0 New array filled .

numpy.zeros(shape, dtype=float, order='C')

2. Parameters :

  • shape: A tuple representing an array dimension
  • dtype: data type
  • order: Yes “C” and “F” Two options

3. example :

Be careful : The default is float Type of

numpy.ones

1. usage :

Create the specified dimension , With 1 New array filled .

numpy.ones(shape, dtype=float, order='C')

2. Parameters :

  • shape: A tuple representing an array dimension
  • dtype: data type
  • order: Yes “C” and “F” Two options

3. example :

numpy.full

1. usage :

Returns a new array of the given dimension and type , fill fill_value.

numpy.full(shape, fill_value, dtype=None, order='C')

2. Parameters :

  • shape: Returns the dimension of the array
  • fill_value: Fill value
  • dtype: Returns the data type of the array , The default value is None finger :np.array(fill_value).dtype
  • order: The order of storage elements in computer memory , Only support ‘C’( Press the line )、‘F’( By column ), Default ‘C’

3. example :


Reference resources :【Python library 】NumPy Detailed tutorial (1):NumPy Array


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved