import numpy as np print (' Specify the data type when generating an array ') arr = np.array([1, 2, 3], dtype =
np.float64) print (arr.dtype) arr = np.array([1, 2, 3], dtype = np.int32) print
(arr.dtype) print ( ) print (' use astype Copy array and convert data type ') int_arr = np.array([1, 2,
3, 4, 5]) float_arr = int_arr.astype(np.float) print (int_arr.dtype) print
(float_arr.dtype) print( ) print (' use astype take float Convert to int The decimal part is discarded ') float_arr =
np.array([3.7, -1.2, -2.6, 0.5, 12.9, 10.1]) int_arr = float_arr.astype(dtype =
np.int) print (int_arr) print( ) print (' use astype Convert a string to an array , If it fails, an exception is thrown .') str_arr
= np.array(['1.25', '-9.6', '42'], dtype = np.string_) float_arr =
str_arr.astype(dtype = np.float) print (float_arr) print() print
('astype Use the data types of other arrays as parameters ') int_arr = np.arange(10) float_arr = np.array([.23,
0.270, .357, 0.44, 0.5], dtype = np.float64) print
(int_arr.astype(float_arr.dtype)) print (int_arr[0], int_arr[1]) #
astype Made a copy , The array itself does not change .

Technology
©2019-2020 Toolsou All rights reserved,
c Language implementation 《 Student management system 》 No hole is the future of mobile phone ? There are still many problems to be solved Junior , A little sense , Just for mutual encouragement How to use Vue Used in Echarts Visual Library The 11th Blue Bridge Cup Java The second provincial competition B Group part Python- be based on OpenCV Contour fill for flooding algorithm hole filling 【C#】 The realization of student achievement information management system List Common interview questions in the collection and simple ideas China Mobile Science Popularization : Why do mobile networks call “ Cellular mobile network ”【Golang Basic series 10 】Go language On conditional sentences if