-2

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

2
  • Please don't post images of code. Post the code as formatted text Commented Dec 19, 2022 at 13:07
  • Please provide your actual code instead of img. Commented Dec 19, 2022 at 13:08

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.