Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>numpy</code> arrays don't play so well with heterogeneous types. When you made <code>data_new</code>, you were storing different kinds of Python objects in it, and so that forced the <code>dtype</code> to be <code>object</code> to be broad enough to handle everything. </p> <pre><code>&gt;&gt;&gt; data array([[ 2.01202031e+13, 2.01202041e+13], [ 5.20000000e+01, 5.30000000e+01], [ -2.20000000e+01, -2.30000000e+01]]) &gt;&gt;&gt; data.dtype dtype('float64') &gt;&gt;&gt; data_new array([[datetime.datetime(2012, 2, 3, 12, 30, 54), datetime.datetime(2012, 2, 4, 12, 30, 54)], [52.0, 53.0], [-22.0, -23.0]], dtype=object) &gt;&gt;&gt; data_new.dtype dtype('O') </code></pre> <p>Since taking the cosine of an arbitrary object doesn't make sense, this isn't implemented:</p> <pre><code>&gt;&gt;&gt; np.cos(data[1]) array([-0.16299078, -0.91828279]) &gt;&gt;&gt; np.cos(data_new[1]) Traceback (most recent call last): File "&lt;ipython-input-87-00101e4be00a&gt;", line 1, in &lt;module&gt; np.cos(data_new[1]) AttributeError: cos </code></pre> <p>You can return to <code>float</code> type (unfortunately it doesn't look like you can use a <code>view</code> with object arrays):</p> <pre><code>&gt;&gt;&gt; np.cos(data_new[1].astype(float)) array([-0.16299078, -0.91828279]) </code></pre> <p>FWIW I prefer <a href="http://pandas.pydata.org" rel="nofollow"><code>pandas</code></a> DataFrames when working with this kind of mixed-type data, but people's preferences vary. I don't know enough about numpy structured arrays to know if you can mix object dtypes and more primitive dtypes, although I didn't think so.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload