Numpy array trims string values
<p>Here is the code I am trying to execute</p>

<pre><code>matrix = []
sample = [10,10,'mike','']
for i in range(10):
    r = [sample] * 3
    matrix.append(r)

matrix = np.array(matrix)
matrix[1][1] = [123,123,'james', 'sdfsdfsdf werwerwer sdfsdfsd werwerwer sdfsdfsdf']
print matrix[1][1]
</code></pre>

<p>and here is what I am getting</p>

<pre><code>['123' '123' 'james' 'sdfsdfsdf w']
</code></pre>

<p>so basically the text is trimmed for some reason. Has anyone seen it before?</p>

<p>Your solution:</p>

<pre><code>matrix[1][1] = [123,123,'james', 'sdfsdfsdf werwerwer sdfsdfsd werwerwer sdfsdfsdf']
matrix = np.array(matrix)
</code></pre>

<p>works only because if you do not specify the data type in the array method, numpy set's it to the smallest size possible to hold all data.</p>

<p>If from an interactice python terminal you typed <code>matrix[1][1]</code> you would have gotten:</p>

<pre><code>array(['123', '123', 'james', 'sdfsdfsdf werwerwer s'], dtype='|S21')
</code></pre>

<p>The dtype indicates that it's a string of length 21 characters.  Which is why your text get's truncated.  When you implement your array structure, you should provide the dtype if you at some point later want to increase the size of the data.</p>

<pre><code>matrix = np.array(matrix, dtype='S50')
matrix[1][1] = [123,123,'james', 'sdfsdfsdf werwerwer sdfsdfsd werwerwer sdfsdfsdf']
print matrix[1][1]

['123' '123' 'james' 'sdfsdfsdf werwerwer sdfsdfsd werwerwer sdfsdfsdf']
</code></pre>

python numpy