numpy

Randomly selecting from Pandas groups with equal probability — unexpected behavior

好久不见. 提交于 2021-02-10 04:45:42
问题 I have 12 unique groups that I am trying to randomly sample from, each with a different number of observations. I want to randomly sample from the entire population (dataframe) with each group having the same probability of being selected from. The simplest example of this would be a dataframe with 2 groups. groups probability 0 a 0.25 1 a 0.25 2 b 0.5 using np.random.choice(df['groups'], p=df['probability'], size=100) Each iteration will now have a 50% chance of selecting group a and a 50%

Numpy / Matplotlib - Transform tick data into OHLCV

我的梦境 提交于 2021-02-10 03:51:56
问题 I have tick data that I wold like to transform in OHLCV(Open, High, Low, Close, Volume) Daily, Hourly, 15min, 5min, 1min. The tick data that I have is like this: array([[u'2011-08-18 13:37:25', u'10.9', u'0.48990826'], [u'2011-08-19 13:19:24', u'11.85', u'0.08438819'], [u'2011-08-19 16:45:01', u'11.5', u'0.4'], ..., [u'2013-08-24 01:29:27', u'107.97', u'0.18523664'], [u'2013-08-24 01:29:35', u'107.98', u'4.61659567'], [u'2013-08-24 01:30:56', u'107.98', u'0.09339562']], dtype='<U19') The

Numpy / Matplotlib - Transform tick data into OHLCV

我们两清 提交于 2021-02-10 03:51:13
问题 I have tick data that I wold like to transform in OHLCV(Open, High, Low, Close, Volume) Daily, Hourly, 15min, 5min, 1min. The tick data that I have is like this: array([[u'2011-08-18 13:37:25', u'10.9', u'0.48990826'], [u'2011-08-19 13:19:24', u'11.85', u'0.08438819'], [u'2011-08-19 16:45:01', u'11.5', u'0.4'], ..., [u'2013-08-24 01:29:27', u'107.97', u'0.18523664'], [u'2013-08-24 01:29:35', u'107.98', u'4.61659567'], [u'2013-08-24 01:30:56', u'107.98', u'0.09339562']], dtype='<U19') The

Numpy / Matplotlib - Transform tick data into OHLCV

徘徊边缘 提交于 2021-02-10 03:49:26
问题 I have tick data that I wold like to transform in OHLCV(Open, High, Low, Close, Volume) Daily, Hourly, 15min, 5min, 1min. The tick data that I have is like this: array([[u'2011-08-18 13:37:25', u'10.9', u'0.48990826'], [u'2011-08-19 13:19:24', u'11.85', u'0.08438819'], [u'2011-08-19 16:45:01', u'11.5', u'0.4'], ..., [u'2013-08-24 01:29:27', u'107.97', u'0.18523664'], [u'2013-08-24 01:29:35', u'107.98', u'4.61659567'], [u'2013-08-24 01:30:56', u'107.98', u'0.09339562']], dtype='<U19') The

Add a index selected numpy array to another numpy array with overlapping indices

寵の児 提交于 2021-02-10 03:44:05
问题 I have two numpy arrays image and warped_image and indices arrays ix,iy . I need to add image to warped_image such that image[i,j] is added to warped_image[iy[i,j],ix[i,j]] . The below code works if the pairs (iy[i,j], ix[i,j]) are unique for all i,j . But when they are not unique i.e. when 2 elements from image need to be added to the same element in warped_image , only one of them gets added. How can I add both elements from image to the same element in warped_image ? Note that, I don't

Add a index selected numpy array to another numpy array with overlapping indices

耗尽温柔 提交于 2021-02-10 03:42:43
问题 I have two numpy arrays image and warped_image and indices arrays ix,iy . I need to add image to warped_image such that image[i,j] is added to warped_image[iy[i,j],ix[i,j]] . The below code works if the pairs (iy[i,j], ix[i,j]) are unique for all i,j . But when they are not unique i.e. when 2 elements from image need to be added to the same element in warped_image , only one of them gets added. How can I add both elements from image to the same element in warped_image ? Note that, I don't

numpy packbits pack to uint16 array

青春壹個敷衍的年華 提交于 2021-02-10 03:05:31
问题 I´ve got a 3D numpy bit array, I need to pack them along the third axis. So exactly what numpy.packbits does. But unfortunately it packs it only to uint8, but I need more data, is there a similar way to pack it to uint16 or uint32? 回答1: Depending on your machine's endianness it is either a matter of simple view casting or of byte swapping and then view casting: >>> a = np.random.randint(0, 2, (4, 16)) >>> a array([[1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 1, 1, 0, 0, 1, 1

numpy packbits pack to uint16 array

懵懂的女人 提交于 2021-02-10 03:02:59
问题 I´ve got a 3D numpy bit array, I need to pack them along the third axis. So exactly what numpy.packbits does. But unfortunately it packs it only to uint8, but I need more data, is there a similar way to pack it to uint16 or uint32? 回答1: Depending on your machine's endianness it is either a matter of simple view casting or of byte swapping and then view casting: >>> a = np.random.randint(0, 2, (4, 16)) >>> a array([[1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 1, 1, 0, 0, 1, 1

Dataframe divide series on pandas

本小妞迷上赌 提交于 2021-02-10 02:40:43
问题 I need to divide each column of the matrix df1 into a single column of the matrix df2 . To get a matrix with dimension df1 (3*2). I need a result: dataframe[[1/6, 2/7, 3/8], [3/6, 4/7, 5,8]] df1 = pd.DataFrame(data = [[1,2,3],[3,4,5]], index = ['a','b'], columns = ['i','ii','iii']) df2 = pd.DataFrame(data = [[6],[7],[8]], index = ['a','b','c'], columns = ['i']) df1.div(df2, axis = 'columns') => does not work for i in range(0,2) a = df1[df1.columns[i]] / df2 => summarizes the result in one

Dataframe divide series on pandas

*爱你&永不变心* 提交于 2021-02-10 02:31:26
问题 I need to divide each column of the matrix df1 into a single column of the matrix df2 . To get a matrix with dimension df1 (3*2). I need a result: dataframe[[1/6, 2/7, 3/8], [3/6, 4/7, 5,8]] df1 = pd.DataFrame(data = [[1,2,3],[3,4,5]], index = ['a','b'], columns = ['i','ii','iii']) df2 = pd.DataFrame(data = [[6],[7],[8]], index = ['a','b','c'], columns = ['i']) df1.div(df2, axis = 'columns') => does not work for i in range(0,2) a = df1[df1.columns[i]] / df2 => summarizes the result in one