@@ -20,7 +20,7 @@ There are 6 general mechanisms for creating arrays:
20206) Use of special library functions (e.g., random)
2121
2222You can use these methods to create ndarrays or :ref: `structured_arrays `.
23- This document will cover general methods for ndarray creation.
23+ This document will cover general methods for ndarray creation.
2424
25251) Converting Python sequences to NumPy arrays
2626==============================================
@@ -29,8 +29,8 @@ NumPy arrays can be defined using Python sequences such as lists and
2929tuples. Lists and tuples are defined using ``[...] `` and ``(...) ``,
3030respectively. Lists and tuples can define ndarray creation:
3131
32- * a list of numbers will create a 1D array,
33- * a list of lists will create a 2D array,
32+ * a list of numbers will create a 1D array,
33+ * a list of lists will create a 2D array,
3434* further nested lists will create higher-dimensional arrays. In general, any array object is called an **ndarray ** in NumPy.
3535
3636::
@@ -72,7 +72,7 @@ results, for example::
7272
7373Notice when you perform operations with two arrays of the same
7474``dtype ``: ``uint32 ``, the resulting array is the same type. When you
75- perform operations with different ``dtype ``, NumPy will
75+ perform operations with different ``dtype ``, NumPy will
7676assign a new type that satisfies all of the array elements involved in
7777the computation, here ``uint32 `` and ``int32 `` can both be represented in
7878as ``int64 ``.
@@ -88,7 +88,7 @@ you create the array.
8888
8989..
9090 40 functions seems like a small number, but the routines.array-creation
91- has ~47. I'm sure there are more.
91+ has ~47. I'm sure there are more.
9292
9393NumPy has over 40 built-in functions for creating arrays as laid
9494out in the :ref: `Array creation routines <routines.array-creation >`.
@@ -104,7 +104,7 @@ dimension of the array they create:
104104
105105The 1D array creation functions e.g. :func: `numpy.linspace ` and
106106:func: `numpy.arange ` generally need at least two inputs, ``start `` and
107- ``stop ``.
107+ ``stop ``.
108108
109109:func: `numpy.arange ` creates arrays with regularly incrementing values.
110110Check the documentation for complete information and examples. A few
@@ -113,16 +113,16 @@ examples are shown::
113113 >>> import numpy as np
114114 >>> np.arange(10)
115115 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
116- >>> np.arange(2, 10, dtype=float )
116+ >>> np.arange(2, 10, dtype=np.float64 )
117117 array([2., 3., 4., 5., 6., 7., 8., 9.])
118118 >>> np.arange(2, 3, 0.1)
119119 array([2. , 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9])
120120
121121Note: best practice for :func: `numpy.arange ` is to use integer start, end, and
122122step values. There are some subtleties regarding ``dtype ``. In the second
123123example, the ``dtype `` is defined. In the third example, the array is
124- ``dtype=float `` to accommodate the step size of ``0.1 ``. Due to roundoff error,
125- the ``stop `` value is sometimes included.
124+ ``dtype=np.float64 `` to accommodate the step size of ``0.1 ``. Due to roundoff error,
125+ the ``stop `` value is sometimes included.
126126
127127:func: `numpy.linspace ` will create arrays with a specified number of elements, and
128128spaced equally between the specified beginning and end values. For
@@ -140,7 +140,7 @@ number of elements and the starting and end point. The previous
140140-------------------------------
141141
142142The 2D array creation functions e.g. :func: `numpy.eye `, :func: `numpy.diag `, and :func: `numpy.vander `
143- define properties of special matrices represented as 2D arrays.
143+ define properties of special matrices represented as 2D arrays.
144144
145145``np.eye(n, m) `` defines a 2D identity matrix. The elements where i=j (row index and column index are equal) are 1
146146and the rest are 0, as such::
@@ -159,7 +159,7 @@ and the rest are 0, as such::
159159the diagonal *or * if given a 2D array returns a 1D array that is
160160only the diagonal elements. The two array creation functions can be helpful while
161161doing linear algebra, as such::
162-
162+
163163 >>> import numpy as np
164164 >>> np.diag([1, 2, 3])
165165 array([[1, 0, 0],
@@ -197,28 +197,28 @@ routine is helpful in generating linear least squares models, as such::
197197 [ 8, 4, 2, 1],
198198 [27, 9, 3, 1],
199199 [64, 16, 4, 1]])
200-
200+
2012013 - general ndarray creation functions
202202--------------------------------------
203203
204204The ndarray creation functions e.g. :func: `numpy.ones `,
205205:func: `numpy.zeros `, and :meth: `~numpy.random.Generator.random ` define
206206arrays based upon the desired shape. The ndarray creation functions
207207can create arrays with any dimension by specifying how many dimensions
208- and length along that dimension in a tuple or list.
208+ and length along that dimension in a tuple or list.
209209
210210:func: `numpy.zeros ` will create an array filled with 0 values with the
211211specified shape. The default dtype is ``float64 ``::
212212
213213 >>> import numpy as np
214214 >>> np.zeros((2, 3))
215- array([[0., 0., 0.],
215+ array([[0., 0., 0.],
216216 [0., 0., 0.]])
217217 >>> np.zeros((2, 3, 2))
218218 array([[[0., 0.],
219219 [0., 0.],
220220 [0., 0.]],
221- <BLANKLINE>
221+ <BLANKLINE>
222222 [[0., 0.],
223223 [0., 0.],
224224 [0., 0.]]])
@@ -228,7 +228,7 @@ specified shape. The default dtype is ``float64``::
228228
229229 >>> import numpy as np
230230 >>> np.ones((2, 3))
231- array([[1., 1., 1.],
231+ array([[1., 1., 1.],
232232 [1., 1., 1.]])
233233 >>> np.ones((2, 3, 2))
234234 array([[[1., 1.],
@@ -265,11 +265,11 @@ dimension::
265265
266266 >>> import numpy as np
267267 >>> np.indices((3,3))
268- array([[[0, 0, 0],
269- [1, 1, 1],
270- [2, 2, 2]],
271- [[0, 1, 2],
272- [0, 1, 2],
268+ array([[[0, 0, 0],
269+ [1, 1, 1],
270+ [2, 2, 2]],
271+ [[0, 1, 2],
272+ [0, 1, 2],
273273 [0, 1, 2]]])
274274
275275This is particularly useful for evaluating functions of multiple dimensions on
@@ -322,15 +322,15 @@ arrays into a 4-by-4 array using ``block``::
322322 [ 0., 0., 0., -4.]])
323323
324324Other routines use similar syntax to join ndarrays. Check the
325- routine's documentation for further examples and syntax.
325+ routine's documentation for further examples and syntax.
326326
3273274) Reading arrays from disk, either from standard or custom formats
328328===================================================================
329329
330330This is the most common case of large array creation. The details depend
331331greatly on the format of data on disk. This section gives general pointers on
332332how to handle various formats. For more detailed examples of IO look at
333- :ref: `How to Read and Write files <how-to-io >`.
333+ :ref: `How to Read and Write files <how-to-io >`.
334334
335335Standard binary formats
336336-----------------------
@@ -397,4 +397,4 @@ knowledge to interface with C or C++.
397397NumPy is the fundamental library for array containers in the Python Scientific Computing
398398stack. Many Python libraries, including SciPy, Pandas, and OpenCV, use NumPy ndarrays
399399as the common format for data exchange, These libraries can create,
400- operate on, and work with NumPy arrays.
400+ operate on, and work with NumPy arrays.
0 commit comments