0 votes
in Python by

explain numpy.fromstring () in Python

1 Answer

0 votes
by
numpy.fromstring () in Python The fromstring() function of Python numpy class creates a new 1-D array initialized from raw binary or text data in a string. Syntax

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

Parameter The numpy.fromstring() method consists of three parameters, which are as follows: string: It represents a string containing the data. dtype: It is an optional parameter. It depicts the data type of returned array, and by default, it is a float. count: This parameter readsthe number of dtype elements from the data. It is an optional parameter, and If this is negative (the default), the count will be determined from the length of the data. sep: It represents the string separating numbers in the data wherein the extra whitespace between elements is also ignored. Return

This function returns the constructed array(ndarray).

Example 1

# Python Programming giving an example for

# numpy.fromstring() function

importnumpy as np

n= np.fromstring('3 5', dtype=int, sep=' ')

print(n)

Output

[3 5]
...