Apr-13-2022, 09:07 PM
I'm new to numpy. I've a string of characters. I'm truncating it one character at a time till only one character is left.
Then I'm trying to fill up a numpy array with these individual substrings in a column wise fashion.
"ValueError: cannot copy sequence with size 4 to array axis with dimension 5"
Can anybody help me solve this problem? Thanks
Then I'm trying to fill up a numpy array with these individual substrings in a column wise fashion.
import numpy as np mystr = 'ASDFL' bs = [mystr[:x+1] for x in range( len( mystr)) ] bs = sorted(bs, key=len, reverse=True ) fm = np.empty(shape=( len(mystr), len(bs) ), dtype='str') for j in range(len(bs)): fm[:, j] = list(bs[j])However I'm getting the following error:
"ValueError: cannot copy sequence with size 4 to array axis with dimension 5"
Can anybody help me solve this problem? Thanks