Convert Integer list to Float Array in Numpy Python by R4R Team

Example-

list is [1,2,3,4,5]
array will [1. 2. 3. 4. 5.]

Syntax-
arr=numpy.array(list,dtype=float)


program-

#import numpy
import numpy as np

#given list
l=[1,2,3,4]
print("Integer list is ",l)

#convert and display
arr=np.array(l,dtype=float)
print("Float array is",arr)


output-

Integer list is [1, 2, 3, 4]
Float array is [1. 2. 3. 4.]

-In this program, we have a list contains integer number, then we convert it into array by np.array() and convert it into float by dtype=float
-then np.arary(l,dtype=float) will convert whole integer list into floating array.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!