I am trying to add an integer to an array but I am getting an error. Here is my code:
import numpy as np
import h5py
for i in range(1, 621):
with h5py.File("C:\\A" + str(i) + ".out") as f:
data = np.array(f['rxs']['rx1']['Ey'])
data.append(0)
np.savetxt("C:\\A" + str(i) + ".csv", data, delimiter = ",")
For this I keep getting an error saying: "AttributeError: 'numpy.ndarray' object has no attribute 'append'"
I have also tried concatenate with an array consisting just 1 integer but it doesn't work. I used these lines for that:
data = np.array(f['rxs']['rx1']['Ey'])
b = np.array([[0]])
np.concatenate(data, b)
I get this error for this one: "TypeError: only integer scalar arrays can be converted to a scalar index"
The original aim of my code is to convert HDF files to CSV files which works if I don't try to change the array.
Could you please help?
np.append(a,0)np.appendis inefficient as it always creates and returns a modified copy of the array. The original array isn't modified.list.appendthis happens only sometimes.np.appendshould be used and when should it be avoided?