Note that there are some explanatory texts on larger screens.

plurals
  1. POPython ValueError: setting an array element with a sequence
    primarykey
    data
    text
    <p>I have a script that I wrote on my machine using Python 3.2, because of the size of the data files involved I need to run it on another machine that runs version 2.5 . When I run the following bit of code that converts a python list to a numpy array I get the following error </p> <pre><code>Traceback (most recent call last): File "count_code2.py", line 119, in &lt;module&gt; cell_centers() File "count_code2.py", line 58, in cell_centers read_file(F) File "count_code2.py", line 44, in read_file Xa = numpy.array(X, dtype=float) #Converts lists to NumPy arrays ValueError: setting an array element with a sequence. </code></pre> <p>the bit of code the error is referring to is</p> <pre><code>Xa = numpy.array(X, dtype=float) #Converts lists to NumPy arrays Ya = numpy.array(Y, dtype=float) Za = numpy.array(Z, dtype=float) </code></pre> <p>Where X, Y and Z are the following Python lists(test lists)</p> <pre><code>X= ['0', '0', '0', '1.5', '0', '0', '0', '0', '0', '0'] Y= ['0', '0', '0', '1', '0', '0', '0', '0', '0', '0'] Z= ['0', '0', '0', '1', '0', '0', '0', '0', '0', '0'] </code></pre> <p>I have tried recasting the dtype as object as I have read in similar posts that this can fix the problem. It does stop the error from being thrown, but another function that sums the data in the arrays returns zeros on the python 2.x machine and gives this error on the 3.2 machine</p> <pre><code>File "C:\Documents and Settings\My Documents\Count_Code.py", line 103, in counter ((ymin &lt;= Ya) &amp; (Ya &lt;= ymax))&amp; TypeError: unorderable types: float() &lt;= str() </code></pre> <p>I am assuming that dtype object turns the list to an array of strings and that is why I get this error. I would like to ask if someone can explain why the differences in versions is causing the errors, and what I can do to work around it. Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    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. 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