1, empty (shape[, Dtype, order])
Returns a new empty array based on the given shape and type (shape[, Dtype, order]).
Parameters:
Shape: integer or integral tuple
Defines the shape of the returned array;
Dtype: Data type, optional
Defines the type of the returned array.
Order: {' C ', ' F '}, optional
Specifies the order in which the array elements are stored in memory: C (C language)-row-major;f (Fortran) column-major.
1234567 |
>>> np.empty([
2
,
2
])
array([[
-
9.74499359e
+
001
,
6.69583040e
-
309
],
[
2.13182611e
-
314
,
3.06959433e
-
309
]])
#random
>>> np.empty([
2
,
2
], dtype
=
int
)
array([[
-
1073741821
,
-
1067949133
],
[
496041986
,
19249760
]])
#random
|
2. Empty_like (a)
Returns a new, empty array based on the shape and type of the given array (a).
Parameters:
A: Array
Its shape and type are used to specify the shape and type of the returned function.
return value:
Output: Ndarray
An array of the same shape and type as the array A.
1234 |
>>> a
=
np.array([[
1.
,
2.
,
3.
],[
4.
,
5.
,
6.
]])
>>> np.empty_like(a)
array([[
-
2.00000715e
+
000
,
1.48219694e
-
323
,
-
2.00000572e
+
000
],
#random
[
4.38791518e
-
305
,
-
2.00000715e
+
000
,
4.17269252e
-
309
]])
|
3. Eye (n[, M, K, Dtype])
Returns a two-dimensional array with a diagonal element of 1 and another element of 0.
Parameters:
N: Integer
Returns the number of rows in the array;
M: integer, optional
Returns the number of columns in the array. If you do not assign a value, the default equals n;
K: integer, optional
Diagonal Serial Number: 0 corresponds to the main diagonal, the integer corresponds to the upper diagonal, the negative numbers correspond to lower diagonal;
Dtype:dtype, optional
Returns the data type of the array
return value:
I:ndarray (N,M)
The element for the K-diagonal of the array is 1, and the other element is 0.
12345678 |
>>> np.eye(
2
, dtype
=
int
)
array([[
1
,
0
],
[
0
,
1
]])
>>> np.eye(
3
, k
=
1
)
array([[
0.
,
1.
,
0.
],
[
0.
,
0.
,
1.
],
[
0.
,
0.
,
0.
]])
|
4. Identity (n[, Dtype])
Returns an n-dimensional unit square.
Parameters:
N: Integer
Returns the number of rows of a phalanx;
Dtype: Data type, optional
Returns the data type of the square, by default, float.
return value:
Output: Ndarray
n x N unit square.
1234 |
>>> np.identity (/ Code>3 array ([[ 1. 0. 0. [ 0. 1. 0. [ 0. 0. 1. |
5, Ones (shape[, Dtype, order])
Returns an array of all 1 elements of a new element, based on the given shape and type (shape[, Dtype, order]).
please refer to zeros for parameter setting.
1234567891011121314 |
>>> np.ones(
5
)
array([
1.
,
1.
,
1.
,
1.
,
1.
]) >>> np.ones((
5
,), dtype
=
np.
int
)
array([
1
,
1
,
1
,
1
,
1
]) >>> np.ones((
2
,
1
))
array([[
1.
],
[
1.
]])
>>> s
=
(
2
,
2
)
>>> np.ones(s)
array([[
1.
,
1.
],
[
1.
,
1.
]])
|
6, Ones_like ()
Returns an array of all 1 elements of a new element, based on the shape and type of the given array (a).
equivalent to A.copy (). Fill (1), please refer to Zeros_like's documentation for specific use.
1234 |
>>> a
=
np.array([[
1
,
2
,
3
], [
4
,
5
,
6
]])
>>> np.ones_like(a)
array([[
1
,
1
,
1
],
[
1
,
1
,
1
]])
|
7, zeros (shape[, Dtype, order])
Returns an array of all 0 elements of a new element, based on the given shape and type (shape[, Dtype, order]).
Parameters:
Shape:int or ints tuples;
Defines the shape of the returned array, such as: (2, 3), or 2.
Dtype: Data type, optional.
Returns the data type of the array, for example: Numpy.int8, default is Numpy.float64.
order:{' C ', ' F '}, optionally, returns the array as multidimensional, in which the elements are arranged in memory in C or Fortran order (row-or columnwise).
Output: Ndarray
An array of data types for the given shape.
123456789101112131415161718 |
>>> np.zeros(
5
)
array([
0.
,
0.
,
0.
,
0.
,
0.
])
>>> np.zeros((
5
,), dtype
=
numpy.
int
)
array([
0
,
0
,
0
,
0
,
0
])
>>> np.zeros((
2
,
1
))
array([[
0.
],
[
0.
]])
>>> s
=
(
2
,
2
)
>>> np.zeros(s)
array([[
0.
,
0.
],
[
0.
,
0.
]])
>>> np.zeros((
2
,), dtype
=
[(’x’, ’i4’), (’y’, ’i4’)])
# custom dtype
array([(
0
,
0
), (
0
,
0
)],
dtype
=
[(’x’, ’<i4’), (’y’, ’<i4’)])
|
8. Zeros_like (a)
Returns an array of all 1 elements of a new element, based on the shape and type of the given array (a).
Equivalent to A.copy (). Fill (0).
Parameters:
A:array_like
Output: Ndarray
A 0 array that is consistent with the shape type of a array.
12345678910111213 |
>>> x
=
np.arange(
6
)
>>> x
=
x.reshape((
2
,
3
))
>>> x
array([[
0
,
1
,
2
],
[
3
,
4
,
5
]])
>>> np.zeros_like(x)
array([[
0
,
0
,
0
],
[
0
,
0
,
0
]])
>>> y
=
np.arange(
3
, dtype
=
np.
float
)
>>> y
array([
0.
,
1.
,
2.
])
>>> np.zeros_like(y)
array([
0.
,
0.
,
0.
])
|
To be edited ....... ....... ...............
The generating array function of the introduction of NumPy functions