matrix | Sololearn: Learn to code for FREE!

0

matrix

hi how can i change the data type of matrix ? the default is float and i want to change into <int> in matrix

6/14/2020 8:01:26 AM

nima rasi

2 Answers

New Answer

+2

nima x Remember that unlike Python lists, NumPy is constrained to arrays that all contain the same type. If types do not match, NumPy will upcast if possible (here, integers are upcast to floating point): input : np.array([3.14, 4, 2, 3]) Output : array([ 3.14, 4. , 2. , 3. ]) ------------------------------------------------------------- If we want to explicitly set the data type of the resulting array, we can use the dtype keyword: import numpy as np a=np.array([ 1., 2., 3., 4.], dtype=int) print(a) print(type(a[0])) output : [1 2 3 4] <class 'numpy.int32'> I hope you understood πŸ™‚

0

thank @kiibo ghayal it works