How to create a NumPy array of arbitrary length strings in Python

Each standard NumPy string array has a maximum length for elements upon initialization and truncates elements to fit that maximum length. An arbitrary length NumPy string array ignores preexisting element length and stores replacement elements without truncation. For example, given an arbitrary length NumPy array with contents [“aaa”, “bbb”, “ccc”], the call np.array[2] = “abcde” updates its contents to [“aaa”, “bbb”, “abcde”].

Solution for How to create a NumPy array of arbitrary length strings in Python : You can use object as a parameter in np.array() Call np.array(dtype = “object”) to create a NumPy array of arbitrary length strings.


how-to-create-a-numpy-array-of-arbitrary-length-strings-in-python