[Python] Why are my Mean, Var, and Std outputs from NumPy different from what the online...

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    The task is:


    You are given a 2-D array of size X. Your task is to find:

    1. The mean along axis
    2. The var along axis
    3. The std along axis

    Input Format The first line contains the space separated values of and . The next lines contains space separated integers.

    Output Format First, print the mean. Second, print the var. Third, print the std.

    Sample Input

    2 2
    1 2
    3 4


    Sample Output

    [ 1.5 3.5]
    [ 1. 1.]
    1.11803398875​

    My code:

    import numpy
    N,M = map(int, input().split(" "))
    A = numpy.array([input().split() for _ in range(N)],int)
    print(numpy.mean(A, axis = 1))
    print(numpy.var(A, axis = 0))
    print(round(numpy.std(A, axis = None),11))


    The output:

    [​IMG]

    I seem to have some indentation issue or my printed result than the expected, there is a space in front of the first vertical elements of the array.

    Am I doing anything wrong?

    Continue reading...

Compartilhe esta Página