The error is because you are incorrectly passing your values to numpy.mean. The method signature is:

`numpy.mean(a, axis=None, dtype=None, out=None, keepdims=<no value>)`

Where `a`

is the array or an iterable object that can be converted into an array. This array contains the values whose average we want to calculate. The second argument is the axis (in case we have a multidimensional array) on which we want to apply the operation (average by rows, by columns, etc).

When in your code you do:

`prom = np.mean(test1, test2)`

you really do:

`prom = np.mean(a=test1, axis=test2)`

when trying to get the elements belonging to the specified axis, NumPy does `a.shape[axis]`

If you have passed as axis test2 which is a float, you have the error shown. Anyway, even without the error, this would calculate the average of `test1`

(a float), which is as expected. `test1`

...

The solution is to simply pass a NumPy array or other container (such as a tuple) with both values as the first argument:

`np.mean((test1, test2))`

On the other hand, a `prom`

(which is a list), you add as a new item the value of `pres`

in each iteration, when you should add in principle the value of the average. Moreover, when doing `prom = np.mean(test1, test2)`

you reassign to the variable `prom`

a scalar (the average), so from that moment on it stops pointing to a list and in the next iteration the call to `prom.append`

will end in an exception.

```
from matplotlib import pyplot as plt
import numpy as np
def simul(pres, maxi, ctrl):
promedios = []
segundos = range(ctrl, 1000 + 1)
print("Resultado:")
for s in segundos:
sinv = np.sin(pres * 2)
cosv = np.cos(pres)
promedio = np.mean((sinv, cosv))
promedios.append(promedio)
print(f"{s} segundos")
print(f"Presion: {pres} mmHg.\n")
print(f"Sin-Cos promedio: {promedio}")
if pres < maxi:
pres += 4
else:
pres -= 15
plt.rcParams["toolbar"] = "None"
plt.plot(segundos, promedios)
plt.title("Aumento de PIC")
plt.ylabel("PIC")
plt.show()
simul(10, 90, 0)
```

0 votes

The error is due to incorrect use of

`numpy.mean`

should be in any case`prom = np.mean((test1, test2))`

. However, in`prom = np.mean()`

you make`prom`

is a scalar, but you define it as a list originally..... I don't quite know what you want to do with this, in the following iteration`prom.append`

will fail...0 votes

@FJSevilla it is supposed to be a graph and I wanted to make an average between the sine and cosine graph but it is my first program working with python but I will investigate more to solve my mistake thanks.

0 votes

Shouldn't you do

`prom.append(np.mean((test1, test2)))`

instead of`prom.append(pres)`

? The error that you originally commented is solved as I said, when doing`np.mean(test1, test2)`

you really do`np.mean(a=test1, axis=test2)`

This causes the failure by passing as axis a float and not an integer. It is solved by putting both values in an iterable, like a tuple.`np.mean((test1, test2))`

which is equivalent to`np.mean(a=(test1, test2))`

or a NumPy array.0 votes

@FJSevilla I already corrected the error according to your advice but I get a new error: AttributeError: 'numpy.float64' object has no attribute 'append'.

0 votes

That's what I'm telling you, above. By doing

`prom = np.mean()`

the variable`prom`

ceases to be a list and becomes a float... If prom is going to store the averages of each iteration you should do in principle what I commented at the beginning of my previous comment0 votes

@FJSevilla ok, I corrected it but I got another error (god I'm getting depressed): UnboundLocalError: local variable 'test1' referenced before assignment

0 votes

Let's continue the discussion in the chat .