user3393463
user3393463

Reputation: 55

Writing a python function that takes mean of array

I am trying to answer the questions below but I don't understand the error code when I run it (Required argument 'object' (pos 1) not found). Any help will be appreciated.

Write a python function that takes in two arrays and returns: a) the mean of the first array

def first_mean(a,b):
    a = np.array()
    b = np.array()
    return np.mean(a)
first_mean([2,3,4],[4,5,6])

b) the mean of the second array

def second_mean(a,b):
    a = np.array()
    b = np.array()
    return np.mean(b)
second_mean([2,3,4],[4,5,6])

c) the Mann-Whitney U-statistic and associated p-value of the two arrays?

def mantest(a,b):
    a = np.array()
    b = np.array()
    return scipy.stats.mannwhitneyu(a,b)
mantest([2,3,4],[4,5,6])

Upvotes: 2

Views: 136

Answers (1)

timgeb
timgeb

Reputation: 78750

You are creating new, empty arrays in your functions for no reason. You are also giving them the same name as your input parameters, thus discarding your original input arrays.

What you are doing boils down to

>>> np.mean(np.array())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Required argument 'object' (pos 1) not found

All you need to do is delete the useless lines

a = np.array()
b = np.array()

from your functions.

Demo:

>>> def first_mean_nobody_knows_why_this_has_two_arguments(a, b):
...     return np.mean(a)
... 
>>> a = np.array([1,2,3])
>>> b = np.array([4,5,6])
>>> first_mean_nobody_knows_why_this_has_two_arguments(a, b)
2.0

Upvotes: 2

Related Questions