indices

Python given numpy array of weights, find indices which split array so that sum of each split is less than value

对着背影说爱祢 提交于 2020-01-06 19:58:16
问题 I have an 1D array of weights, w and an array of capacities c of the same shape as w. I need to find the smallest array of indices such that when w is split by these indices, the cumsums of split arrays less than the corresponding capacities in c. Given an array of weights and capacities as follows: w = [1,2,3,4,5,6]; c = [3, 12, 7, 6, 12] I need to find the smallest number of indices 'i' so that the cumsums of split arrays less than the corresponding capacities in c. In this case, i = [2, 3,

Python given numpy array of weights, find indices which split array so that sum of each split is less than value

别说谁变了你拦得住时间么 提交于 2020-01-06 19:58:04
问题 I have an 1D array of weights, w and an array of capacities c of the same shape as w. I need to find the smallest array of indices such that when w is split by these indices, the cumsums of split arrays less than the corresponding capacities in c. Given an array of weights and capacities as follows: w = [1,2,3,4,5,6]; c = [3, 12, 7, 6, 12] I need to find the smallest number of indices 'i' so that the cumsums of split arrays less than the corresponding capacities in c. In this case, i = [2, 3,

Join elasticsearch indices while matching fields in nested/inner objects

本小妞迷上赌 提交于 2020-01-05 07:43:14
问题 I am trying to join 2 elasticsearch indices by using terms filter lookup. I referred to http://www.elasticsearch.org/blog/terms-filter-lookup/ and http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html. These Examples lookup on an array of fields like "followers" : ["1", "3"] and join works fine for similar data. My requirement is to join with a field inside an array of objects. When I extend the above example to include an array of objects, my query

GLubyte vs GLshort for Indices

我们两清 提交于 2020-01-05 02:27:12
问题 Looking through documentation for vertex arrays in OpenGL, two of the most common memory types used for indices I found were GLubyte (GL_UNSIGNED_BYTE) and GLshort (GL_SHORT). I was wondering if there was any actual difference between using the two for indices Thanks, Dragonwrenn 回答1: GL_UNSIGNED_BYTE is OK for models which have at most 256 vertices - that's really not many. GL_UNSIGNED_SHORT , taking 2 bytes, would limit you to 65536 vertices - still that's kind of few. I'd say the most

How to efficiently generate lower triangle indices of a symmetric matrix

偶尔善良 提交于 2020-01-02 06:29:50
问题 I need to generate lower triangle matrix indices (row and columns pairs). The current implementation is inefficient (memory wise) specially when symmetric matrix gets big (more than 50K rows). Is there a better way? rows <- 2e+01 id <- which(lower.tri(matrix(, rows, rows)) == TRUE, arr.ind=T) head(id) # row col # [1,] 2 1 # [2,] 3 1 # [3,] 4 1 # [4,] 5 1 # [5,] 6 1 # [6,] 7 1 回答1: Here's another approach: z <- sequence(rows) cbind( row = unlist(lapply(2:rows, function(x) x:rows), use.names =

Print a matrix without row and column indices

霸气de小男生 提交于 2019-12-30 06:10:09
问题 If I print a matrix, it is shown with row and column indices in the console. E.g. > print(diag(3)) [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 How can I suppress the column and row indices? I.e. something like this: > print(diag(3), indices=FALSE) 1 0 0 0 1 0 0 0 1 I can see that the cwhmisc package should contain a printM function to do this according to the documentation but it is not there when I load cwhmisc. Also, this seems like something you should be able to to in base R. 回答1: The

Print a matrix without row and column indices

北慕城南 提交于 2019-12-30 06:10:03
问题 If I print a matrix, it is shown with row and column indices in the console. E.g. > print(diag(3)) [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 How can I suppress the column and row indices? I.e. something like this: > print(diag(3), indices=FALSE) 1 0 0 0 1 0 0 0 1 I can see that the cwhmisc package should contain a printM function to do this according to the documentation but it is not there when I load cwhmisc. Also, this seems like something you should be able to to in base R. 回答1: The

MATLAB - Perform operation on matrix indices without a for loop

五迷三道 提交于 2019-12-25 07:19:11
问题 It's been a little while since I've done matrix operations in MATLAB, so please forgive me if this is easily solvable. I have some NxM matrix A , and I would like to perform an operation on the column indices of A . I know how to do this using a for loop, but since I'm using MATLAB I'd like to make use of MATLAB's ability to do operations on matrices fast. Suppose I have a function called myFunc . Is there a way to do the following without a for loop (such as with matrix multiplication): for

Get indices of all character elements matches in string in R

 ̄綄美尐妖づ 提交于 2019-12-25 01:43:45
问题 I want to get indices of all occurences of character elements in some word. Assume these character elements I look for are: l , e , a , z . I tried the following regex in grep function and tens of its modifications, but I keep receiving not what I want. grep("/([leazoscnz]{1})/", "ylaf", value = F) gives me numeric(0) where I would like: [1] 2 3 回答1: To use grep work with individual characters of a string, you first need to split the string into separate character vectors. You can use

Get vector indices before-and-after (window +/- 1) given indices

淺唱寂寞╮ 提交于 2019-12-24 20:58:51
问题 What's the best Matlab/Octave idiom, given idx a vector of indices, to get the sorted vector of idx +/-1 ? I have an n x 7 data matrix, column 3 is an integer label, and I'm interested in viewing the neighborhood of discontinuities on it. Hence I get the corresponding indices: idx = find(diff(data(:,3)) > 0) 5297 6275 6832 ... 20187 Then if I want to view that neighborhood +/- 1 on my column (e.g. on the (mx2) matrix [idx-1; idx+1] ), I need to form the vector of idx-1, idx+1 either