How to convert a string to numpy array?

497383676:
xyzf

Converting string to numpy array

Given a string abcxyz, I want it to return a numpy array like:

array(["a", "b", "c", "x", "y", "z"]). 

I have tried fromstring

Bingrid = np.fromstring(elements, dtype=str) 

but it returns

ValueError: Zero-valued itemsize.

Nick ODell

Use list().

import numpy as np
s = "abcxyz"
print(np.array(list(s)))

Output:

['a' 'b' 'c' 'x' 'y' 'z']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert numpy array to string and vice versa

how to convert lists in string in numpy array to a numpy array

Convert string to numpy array

Convert string array to numpy array

Convert a string with brackets to numpy array

Convert python string into numpy array

Convert elements in a numpy array to string

Convert string to numpy array of strings

Convert string back to numpy array

convert string value to numpy array

convert a big numpy array to string

How to convert string representation of list in pandas series to a numpy array?

How to convert vector wrapped as string to numpy array in pandas dataframe?

How do I convert a PNG string into a Numpy array?

How to convert the string between numpy.array and bytes

How to convert elements type in numpy array from string to int

Python How to convert the numpy array(dtype=uint16) to a string?

How to convert string into numpy array for tensorflow and vice versa

How to convert a NumPy array to a string with the same format it can be set with?

convert string numpy array to a ascii numpy matrix

How to convert numpy array saved as string in pandas csv file back to a numpy array?

Convert numpy array of array to dataframe of string

convert string representation of array to numpy array in python

Convert an array stored as a string, to a proper numpy array

How to convert string formed by numpy.array2string back to array?

How to convert a string into an array?

How to convert this String to Array?

How to string convert to array

How to convert string to an array