![]() |
VOOZH | about |
fromiter() function creates a NumPy array from any iterable. It is useful for converting data from sources like generators or files into an array for further processing.
Syntax:
numpy.fromiter(iterable, dtype, count = -1)
Parameters:
Returns: [ndarray] The output array.
Numpy.fromiter() function creates a Numpy array from an iterable object. where each element is converted and stored in the array. Here is an example of to use 'numpy.fromiter()':
[1 2 3 4 5 6]
Example 1: Using the numpy.fromiter() function to create a NumPy array from an iterable generated by a generator expression.
[ 0 1 8 27]
Example 2: The NumPy array gfg containing the elements generated by the generator expression. In this case, it's the squares of the numbers from 0 to 5.
[ 0. 1. 4. 9. 16. 25.]
To create a Numpy array from Unicode charcters using 'numpy.froiter()', you can pass an iterable of Unicode strings as input.Each Unicode string can be represented using its corresponding code point.
['G' 'e' 'e' 'k']
In Numpy the 'U2' data type reprsents Unicode strings with a fixed length of 2 characters.The 'U' indicates that the data type in Unicode, and the number '2' specifies the length of each string.
Here's an example of to use 'U2' in numpy:
['p' 'y' 't' 'h' 'o' 'n']