79215753

Date: 2024-11-22 16:14:37
Score: 0.5
Natty:
Report link

Your issue is that dtype=str defaults to strings of length 1. Fix it by specifying the max length:

import numpy as np
row_length = 5
col_length = 3

# Specify the maximum string length (e.g., 10 characters)
x = np.empty([row_length, col_length], dtype='<U10') 
x[1, 2] = 'ddd'
print(x)
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Gabriel Brandao