简体   繁体   中英

How to easily extract numpy arrays (Matrices) from python to excel?

Fairly new to coding. I am working on a code and the outcome is below. How do I extract this output as an excel file or Mathematica format (which I reckon would be in C code)? I have come across USA Panda but it looked far too complex.

Here is an example of one of the matrices:

[[ 153181.46111548  -21602.51374705  -76590.73055774  -54988.21681068
    65298.50746269    -490.96622152  -65298.50746269     490.96622152]
 [ -21602.51374705  153181.46111548  -54988.21681068  -76590.73055774
      490.96622152  -65298.50746269    -490.96622152   65298.50746269]
 [ -76590.73055774  -54988.21681068  153181.46111548  -21602.51374705
   -65298.50746269     490.96622152   65298.50746269    -490.96622152]
 [ -54988.21681068  -76590.73055774  -21602.51374705  153181.46111548
     -490.96622152   65298.50746269     490.96622152  -65298.50746269]
 [  65298.50746269     490.96622152  -65298.50746269    -490.96622152
   283778.47604085  108994.50117832 -141889.23802042 -250883.73919874]
 [   -490.96622152  -65298.50746269     490.96622152   65298.50746269
   108994.50117832  283778.47604085 -250883.73919874 -141889.23802042]
 [ -65298.50746269    -490.96622152   65298.50746269     490.96622152
  -141889.23802042 -250883.73919874  283778.47604085  108994.50117832]
 [    490.96622152   65298.50746269    -490.96622152  -65298.50746269
  -250883.73919874 -141889.23802042  108994.50117832  283778.47604085]]

Assuming you are using NumPy as per your question title you could use the following Dump a NumPy array into a csv file you can use numpy numpy.savetxt

This would result in the following code:

import numpy

numpy.savetxt('your\location\yourfile.csv', numpy_array,  delimiter=',')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM