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

Asked By: jing_520713

||

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

Answered By: Ashok Murugan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.