Open In App

numpy.fromstring() function – Python

Last Updated : 18 Aug, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

numpy.fromstring() function create a new one-dimensional array initialized from text data in a string.

Syntax : numpy.fromstring(string, dtype = float, count = -1, sep = ' ')

Parameters :

string : [str] A string that contained the data.

dtype : [data-type, optional] Data-type of the array. Default data type is float.

count : [int, optional] Number of items to read. If this is negative (the default), the count will be determined from the length of the data.

sep : [str, optional] The string separating numbers in the data.

Return : [ndarray] Return the constructed array.

Code #1 :

Python3
# Python program explaining
# numpy.fromstring() function
 
# importing numpy as geek
import numpy as geek
 
gfg = geek.fromstring('1 2 3 4 5', dtype = float, sep = ' ')
 
print(gfg)

Output :

[1. 2. 3. 4. 5.]

Code #2 :

Python3
# Python program explaining
# numpy.fromstring() function
 
# importing numpy as geek
import numpy as geek
 
gfg = geek.fromstring('1 2 3 4 5 6', dtype = int, sep = ' ')
 
print(gfg)

Output :

[1 2 3 4 5 6]


Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy