A Python list of Numpy Arrays to CSV?
<p>I have a Python list of Numpy arrays storing X, Y, Z coordinates - like this:</p>

<pre><code>[array([-0.22424938,  0.16117005, -0.39249256])
array([-0.22424938,  0.16050598, -0.39249256])
array([-0.22424938,  0.1598419 , -0.39249256]) ...,
array([ 0.09214371, -0.26184322, -0.39249256])
array([ 0.09214371, -0.26250729, -0.39249256])
array([ 0.09214371, -0.26317136, -0.39249256])]
</code></pre>

<p>And I would like to get them into a CSV file so I can plot them in GIS software.  I am new to Numpy arrays and I keep getting errors using methods like numpy.ndarray.tofile().  </p>

<p>I can iterate the list using </p>

<pre><code>for item in list:
    f.write(str(item))
</code></pre>

<p>but it writes the data to the text file as binary data.<br>
I just want to have each XYZ value comma separated with each row storing one XYZ value. 
Any help is appreciated.</p>

<p>Use the <a href="https://docs.python.org/2/library/csv.html#module-csv" rel="nofollow"><code>csv</code></a> module with its <a href="https://docs.python.org/2/library/csv.html#csv.csvwriter.writerows" rel="nofollow"><code>writerows</code></a> method:</p>

<pre><code>import csv

with open('my_data.txt', 'w') as f:
    csvwriter = csv.writer(f)
    csvwriter.writerows(list_of_arrays)
</code></pre>

python arrays csv numpy