title: How to change the dtype of a numpy array to 'object'?
body: <p>My goal is to do this:</p>
  
  <pre><code>weights[1][0][0] = some_object(1)
  </code></pre>
  
  <p>But it throws this error:</p>
  
  <pre><code>TypeError: float() argument must be a string or a number, not 'some_object'
  </code></pre>
  
  <p>Because of this I wawnt to change the dtype to 'object'
  In my code I have weights. They look like this:</p>
  
  <pre><code>&gt;&gt;&gt; print(weights)
  [ array([[-2.66665269,  0.        ],
     [-0.36358187,  0.        ],
     [ 1.55058871,  0.        ],
     [ 3.91364328,  0.        ]])
    array([[ 0.],
     [ 0.]])]
  </code></pre>
  
  <p>I want to change <code>weights[1][0][0]</code> to an object. I am refering to the 0 in:</p>
  
  <pre><code>[ array([[-2.66665269,  0.        ],
     [-0.36358187,  0.        ],
     [ 1.55058871,  0.        ],
     [ 3.91364328,  0.        ]])
    array([[ 0.],                        #this zero right here
     [ 0.]])]
  </code></pre>
  
  <p>I want to convert that 0 to some_object(1). So I change the dtype to 'object', but it remains float!</p>
  
  <pre><code>&gt;&gt;&gt; weights=np.array(weights,dtype='object')
  &gt;&gt;&gt; weights.dtype
  object
  &gt;&gt;&gt; weights[1].dtype
  float64
  &gt;&gt;&gt; weights[1][0].dtype
  float64
  &gt;&gt;&gt; weights[1][0][0].dtype
  float64
  </code></pre>
  
  <p>So now I try:</p>
  
  <pre><code>&gt;&gt;&gt; weights[1].dtype='object'
  TypeError: Cannot change data-type for object array.
  </code></pre>
  
  <p>and this</p>
  
  <pre><code>&gt;&gt;&gt; weights[1][0].dtype='object'
  TypeError: Cannot change data-type for object array.
  </code></pre>
  
  <p>so now I cannot do this:</p>
  
  <pre><code>weights[1][0][0] = some_object(1)
  TypeError: float() argument must be a string or a number, not 'object'
  </code></pre>
  
  <p>because the dtype is incorrect. How do I change the dtype?</p>
  
  <p>Edit: I found an answer.</p>
  
  <pre><code>weights[1] = weights[1].tolist()
  weights[1][0][0] = some_object(1)
  ....
  weights=np.array(weights) 
  </code></pre>