79221285

Date: 2024-11-25 00:03:10
Score: 1.5
Natty:
Report link

Ok, found an explanation here https://note.nkmk.me/en/python-numpy-dtype-astype/ Scroll down to "The number of characters in strings"

numpy creates the array with the maximum number of characters allowed in an element = the longest element. In my case this is 3. That is what dtype='<U3' indicates when you print the array. To allow additional characters in an element specify the datatype as dtype = 'U#' where # is the number of characters desired. I want to substitute "high" for "low" so dtype = 'U4' will work as indicated in the code below:

import numpy as np

X = np.array(["low"]*10, dtype = 'U4')
X

This returns: array(['low', 'low', 'high', 'low', ...])

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: ThackeryW