How to enter string in python two-dimensional array
Question:
Why do I get only the first character in the result?
enter image description here
label = np.empty([17,2],dtype=str)
label[1][1]="asd"
label[2][1]="asd"
print(label)
I don’t know if np.empty can input a string
Answers:
you can use dtype=’object’ instead of ‘str’
test = np.empty((2,2), dtype=’object’)
test[0,0] = "ashok"
print(test)
Explanation : actually string is object which hold the character array values. so by default indexing in string location the first char not whole string.
example
Why do I get only the first character in the result?
enter image description here
label = np.empty([17,2],dtype=str)
label[1][1]="asd"
label[2][1]="asd"
print(label)
I don’t know if np.empty can input a string
you can use dtype=’object’ instead of ‘str’
test = np.empty((2,2), dtype=’object’)
test[0,0] = "ashok"
print(test)
Explanation : actually string is object which hold the character array values. so by default indexing in string location the first char not whole string.
example