I have a problem that I can't find a solution to no matter how many times I think about it. I have a program in which I generate a series of data and store them in a list. Later on I have to delete some of the items in the list to make it smaller in size. I always remove the first or last item in the list and I use the "del" or "pop" functions.
To generate the list I want to work on, I call a function I created that returns a list. Something like this:
y = generadatos(a1,a2,a3) del y
When it reaches the line with the "del" the program hangs. I have tried to do it from the console by typing del y and I get the following error:
ValueError: cannot delete array elements
However if I open a new sheet and create this simple code it works without problems:
a=[1,2,3,4] del a print a
If instead of using "del" I use "pop" the same thing happens. I thought that maybe the list returned by the function that generates the data does something that I don't understand and that's why it doesn't let me delete elements.
Thank you very much.
The "generadata" function is this:
def generadatos(nst,p0st,ast,lbst,timesstrst,pvst,incremst): xbigst = 0 xsmallst = 0 I0bigst =  I0smallst =  for ist in range(0,nst+1): pst = p0st + ast*ist pbigst = np.abs((pst*pvst)/(pst-pvst)) psmallst = np.abs((pst*pvst)/(pst+pvst)) limitpbigst = pbigst/lbst limitpbigst = np.int(limitpbigst) halflimitpbigst = np.int(limitpbigst/2) limitpsmallst = psmallst/lbst limitpsmallst = np.int(limitpsmallst) halflimitpsmallst = np.int(limitpsmallst/2) for jst in range(0,timesstrst): for kst in range(0,halflimitpbigst): I0bigst.append(1) xbigst = xbigst + 1 for lst in range(halflimitpbigst,limitpbigst): I0bigst.append(0) xbigst = xbigst + 1 for mst in range(0,halflimitpsmallst): I0smallst.append(1) xsmallst = xsmallst + 1 for ost in range(halflimitpsmallst,limitpsmallst): I0smallst.append(0) xsmallst = xsmallst + 1 limitpbig2st = np.int((pbigst/2)/lbst) for qst in range (0,limitpbig2st): del I0bigst[-1] limitpsmall2st = np.int((psmallst/2)/lbst) for rst in range (0,limitpsmall2st): del I0smallst[-1] if incremst > 0: aux1st = I0bigst[::] I0bigst = aux1st[::-1] else: aux1st = I0smallst[::] I0smallst = aux1st[::-1] I0st = np.append(I0smallst,I0bigst) return I0st`
At first I create empty lists in the style of
I0 =  . Then I add data to it using `I0.append(value) And at the end I use NumPy's function I0st = np.append(I0smallst,I0bigst)