I am new to Python, so apologies if my question is very basic, but this is driving me crazy.
So, I created a 2D numpy array of floats, with a string row header. I would like to save the array so that I could re-open it and work it later.
I tried to use np.savetxt as follows:
np.savetxt('1_array', waves)
but it gives the obvious error:
TypeError: Mismatch between array dtype ('|S11') and format specifier ('%.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e %.18e')
I looked for a solution, but I don't seem to find any that would be appropriate for my case. Intuitively, there should be a way to specify the only the first row is a string, but I couldn't figure out how to do this.
Any help will be greatly appreciated!
headerparameter innp.savetxt?np.savetxt('1_array', waves, header=waves[0]), but it gives me the error: AttributeError: 'numpy.ndarray' object has no attribute 'replace'headerneeds to be a string, not a numpy array. 2. ifwaves[0]is your header,wavesis still in string format, and you haven't split your data out. Alsowaves[0]is part ofwaves, so you're just duplicating your header.