Skip to content

Instantly share code, notes, and snippets.

@glemaitre
Created February 27, 2020 21:48
Show Gist options
  • Save glemaitre/a5f76135a8426d892a264a0b93edcc40 to your computer and use it in GitHub Desktop.
Save glemaitre/a5f76135a8426d892a264a0b93edcc40 to your computer and use it in GitHub Desktop.
In [1]: import numpy as np
In [2]: X = ["One", "string"]
In [3]: X
Out[3]: ['One', 'string']
In [4]: X[0]
Out[4]: 'One'
In [5]: type(X[0])
Out[5]: str
In [6]: X = np.array(X)
In [7]: X
Out[7]: array(['One', 'string'], dtype='<U6')
In [8]: X[1] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
In [9]: X
Out[9]: array(['One', 'xxxxxx'], dtype='<U6')
In [10]: X = X.astype(object)
In [11]: X
Out[11]: array(['One', 'xxxxxx'], dtype=object)
In [12]: X[1] = "yyyyyyyyyyyyyyyyyy"
In [13]: X
Out[13]: array(['One', 'yyyyyyyyyyyyyyyyyy'], dtype=object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment