np.std (Array) # overall standard deviation np.std (Array, ddof =. 1) # Sample standard deviation
# 中位数 import numpy as np import datetime as dt def dmy2ymd(dmy): """ 把日月年转年月日 :param day: :return: """ dmy = str(dmy, encoding='utf-8') t = dt.datetime.strptime(dmy, '%d-%m-%Y') s = t.date().strftime('%Y-%m-%d') return s dates, opening_prices, \ highest_prices, lowest_prices, \ closing_prices, volumes = \ np.loadtxt('aapl.csv ' , DELIMITER = ' , ' , usecols = (. 1,. 3,. 4,. 5,. 6,. 7 ), the unpack = True, DTYPE = ' M8 [D], F8, F8, F8, F8, F8 ' , Converters = {. 1: dmy2ymd}) # DMY transfer date # overall standard deviation entertained std_c = np.std (closing_prices) Print (std_c) # 7.080008325481608 # overall standard deviation opening std_o = np.std (opening_prices) Print (std_o) #7.099438350242144 std_c2 = np.std (closing_prices, ddof =. 1) # Sample standard deviation Print (std_c2) # 7.201042876260849 # implemented manually m = np.mean (closing_prices) # arithmetic mean D = closing_prices - m # spreads v = np. Mean (D ** 2) # deviation side S = np.sqrt (V) # population standard deviation Print (S) # 7.080008325481608 V2 = (D ** 2) .sum () / (d.size -. 1 ) S2 = np.sqrt (V2) Print (S2) # sample standard deviation # 7.201042876260849