I am combining column data from three different input arrays into a new csv. To do so I am using the NumPy stack function. Right now I have a [12,3] stacked NumPy array that I am trying to export to a csv.
VI_Samples_v4 = numpy.stack((samplename,sample_start_date,sample_type_code), axis =1)
When I use the numpy save text
numpy.savetxt('array.csv', [VI_Samples_v4], fmt='%s', delimiter=',')
I get this Error: "ValueError: Expected 1D or 2D array, got 3D array instead." I am fairly certain it is a 2D array. When I ask Numpy for the array shape, I get (12,3).
VI_Samples_v4.shape
What's my error, then?
The problem is the square brackets you've placed around your array in the call to numpy.savetxt
. By passing a list containing your 2D array, you're causing numpy.savetxt
to read it as a 3D array. Just pass the array without the square brackets like so:
numpy.savetxt('array.csv', VI_Samples_v4, fmt='%s', 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.