Sort by

recency

|

68 Discussions

|

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import sys
    import numpy as np
    from scipy import stats
    
    # Read Data
    data = sys.stdin.read().splitlines()
    nums = data[1].split(' ')
    nums = np.array([int(num) for num in nums])
    
    # Calculate Stats
    mean = np.mean(nums)
    median = np.median(nums)
    mode = stats.mode(nums)[0]
    std = np.std(nums)
    z = 1.96
    std_error = (std/(np.sqrt(len(nums))))
    lower = mean - z*std_error
    upper = mean + z*std_error
    
    # Print Output
    print(f"{mean:.1f}")
    print(f"{median:.1f}")
    print(mode)
    print(f"{std:.1f}")
    print(f"{lower:.1f} {upper:.1f}")
    
  • + 0 comments
    num_int = int(input())
    string_nums = input()
    
    # Converting string_nums to list:
    string_list = string_nums.split()
    int_string_list = list(map(int, string_list))
    
    calc_mean = st.mean(int_string_list)
    calc_median = st.median(int_string_list)
    calc_mode = st.multimode(int_string_list)
    min_calc_mode = min(calc_mode)
    calc_std = st.pstdev(int_string_list)
    calc_std_round = round(calc_std, 1)
    
    # bounds:
    length = len(int_string_list)
    interval = 1.96 * (calc_std / length ** 0.5)
    ub = calc_mean + interval
    round_ub = round(ub, 1)
    lb = calc_mean - interval
    round_lb = round(lb, 1)
    
    print(calc_mean)
    print(calc_median)
    print(min_calc_mode)
    print(calc_std_round)
    print(round_lb, round_ub)
    
    
    
  • + 0 comments

    `Packages Used

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    def median(x):
        x = sorted(x)
        length = len(x)
        if length % 2 == 0: 
            half_length = (length // 2)
            median = (x[half_length - 1] + x[half_length]) / 2
        else:   
            half_length = length // 2
            median = x[half_length]
        return median
        
    def mean(x):
        length = len(x)
        return sum(x) / length
        
        
    def mode(x):
        counter = {}
        for val in x:
            counter[val] = counter.get(val, 0) + 1
        
        max_frequency = max(counter.values())
        modes = [k for k, v in counter.items() if v == max_frequency]
        
        # If multiple elements have the same max frequency, return the smallest one
        return int(min(modes))
            
    def std(x):
        x_mean = mean(x)
        x_std = (sum(((val - x_mean) ** 2 for val in x)) / len(x)) ** 0.5
        return x_std
            
    
    def confidence_interval(x):
        x_mean = mean(x)
        x_std = std(x)
        length = len(x)
        interval = 1.96 * (x_std / (length ** 0.5))
        
        lower, upper = x_mean - interval, x_mean + interval
        
        return lower, upper, 1
    
    if __name__ == '__main__':
    
        length = input()
        values = [float(val) for val in input().split(" ")]
        print(mean(values))
        print(median(values))
        print(mode(values))
        print(round(std(values), 1))
        print(round(confidence_interval(values)[0], 1), round(confidence_interval(values)[1], 1))
    
  • + 0 comments

    import numpy as np from collections import Counter import math

    n = int(input()) array = np.array(input().split(),int)

    mean = round(np.mean(array),1) median = round(np.median(array),1) std = round(np.std(array),1)

    count = Counter(array) max_count = max(count.values())

    mode = min([num for num, freq in count.items() if freq == max_count])

    def calculate_confidence_interval(mean, std, N, z_score=1.96): lower_confidence = round((mean - z_score * (std / math.sqrt(N))), 1) upper_confidence = round((mean + z_score * (std / math.sqrt(N))), 1) return lower_confidence, upper_confidence

    lower, upper = calculate_confidence_interval(mean, std, n)

    print(mean) print(median) print(mode) print(std) print(lower, upper)

  • + 0 comments

    You can use these statistical calculations to provide valuable insights. For example, you could calculate and display the average age of pets, identify the most common pet breeds, determine size variation, and even assess the confidence interval for pet-related statistics. These insights can help pet owners and enthusiasts make informed decisions and gain a better understanding of the pet community.