Function call method:
(shape, dtype=float)
Individual parameter significance:
- shape: the shape (dimension) of the new array created.
- dtype: the data type of the new array to be created.
- Return value: an all-zero array of the given dimension.
Basic Usage:
import numpy as np array = ([2, 3]) print(array) print() """ result: [[0. 0. 0.] [0. 0. 0.]] float64 """
You can see that we have successfully created an all-zero two-dimensional array with 2 rows and 3 columns. And the data type in the created array is of type np.float64.
Advanced Usage:
import numpy as np array = ([2, 3], dtype=np.int32) print(array) print() """ result: [[0 0 0] [0 0 0]] int32 """
As you can see, here again we have successfully created an all-zero 2D array with 2 rows and 3 columns. And we have specified its data type as np.int32.
Top Usage:
import numpy as np # Create rain data n_drops = 10 rain_drops = (n_drops, dtype=[('position', float, (2,)), ('size', float), ('growth', float), ('color', float, (4,))]) # Initialize the raindrops in random positions and with # random growth rates. rain_drops['position'] = (0, 1, (n_drops, 2)) rain_drops['growth'] = (50, 200, n_drops) print(rain_drops) """ result: [([0.70284885, 0.03590322], 0., 176.4511602 , [0., 0., 0., 0.]) ([0.60838294, 0.49185854], 0., 60.51037667, [0., 0., 0., 0.]) ([0.86525398, 0.65607663], 0., 168.00795695, [0., 0., 0., 0.]) ([0.25812877, 0.14484747], 0., 80.17753717, [0., 0., 0., 0.]) ([0.66021716, 0.90449213], 0., 121.94125106, [0., 0., 0., 0.]) ([0.88306332, 0.51074725], 0., 92.4377108 , [0., 0., 0., 0.]) ([0.68916433, 0.89543162], 0., 90.77596431, [0., 0., 0., 0.]) ([0.7105655 , 0.68628326], 0., 144.88783652, [0., 0., 0., 0.]) ([0.6894679 , 0.90203559], 0., 167.40736266, [0., 0., 0., 0.]) ([0.92558218, 0.34232054], 0., 93.48654986, [0., 0., 0., 0.])] """
to this article on the use of () function is introduced to this article, more related () use content please search for my previous articles or continue to browse the following related articles I hope that you will support me more in the future!