Coding #:. 8 UTF- # numpy ndarry: a multi-dimensional array of objects Import numpy NP AS # to generate a random array data np.random.randn = (2,. 3) data # add data to a series of mathematical operations data 10 * data + data # Array the dtype attributes used to describe the data type array data.shape data.dtype # generated array ndarray DATAl = [. 6, 7.5,. 8, 0,. 1] of arr1 = np.array (DATAl) of arr1 DATA2 = [[. 1, 2 ,. 3,. 4], [. 5,. 6,. 7,. 8]] arr2 is = np.array (DATA2) arr2 is # ndim shape by checking array property arr2.ndim arr2.shape arr1.dtype arr2.dtype # other array generating function np.zeros (10) np.zeros ((. 3,. 6)) np.empty ((2,. 3, 2)) np.arange (15) np.ones ((2,. 3)) # Ndarry data type Import numpy AS NP of arr1 np.array = ([. 1, 2,. 3], DTYPE = np.float64) arr2 is np.array = ([. 1, 2,. 3], DTYPE = np.int32) of arr1. DTYPE arr2.dtype # asType method of converting an array of data type # integer to Floating- ARR = np.array ([. 1, 2,. 3,. 4,. 5]) ARR arr.dtype float_arr = arr.astype (NP. float64) float_arr.dtype # floating point to integer conversion ARR = np.array ([1.2, 2.4, 0.3, -1.4, 15.6]) ARR arr.astype (np.int32) # string into a number numeric_strings = np .Array ([ '1.25', '-9.6', '42 is'], dtype = np.string_) numeric_strings.astype (a float) # another property using the dtype array int_array = np.arange (10) calibers = np.array ([. 22, .270 , .357, .380, .44, .50 ], dtype = np.float64) int_array.astype (calibers.dtype) # incoming data using the type code Type empty_uint32 np.empty = (. 8, DTYPE = 'U4') empty_uint32 # numpy array arithmetic arr = np.array ([[1. , 2., 3 .], [4., 5. the, 6. the]]) ARR # multiplying ARR ARR * # subtraction ARR-ARR # with the calculated scalar arithmetic operations . 1 / ARR ARR ** 0.5 between the same size array # Comparative arr2 is np.array = ([[0., 4., 1.], [7. The, 2., 12. The]]) arr2 is arr2 is> ARR
Reference books: Data analysis was performed using the python
Author: Zhou Hua 520
Source: https: //www.cnblogs.com/xfzh193/
In this paper, learn, share, research and exchange-based, welcome to reprint, please indicate the source author!