indices

Finding the start and stop indices in sequence in R

旧时模样 提交于 2019-12-06 09:52:44
Suppose I have the sequence: x = c( 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0) Is there an elegant way in R to return the start and stop indices of each sequence of 1s? The answer should be a 2 column array with nRows = number of sequences of 1s: startIndx = [ 1, 5, 7 ] stopIndex = [ 2, 5, 9 ] Thanks. BSL Assuming your vector consists of 0 and 1 values: which(diff(c(0L, x)) == 1L) #[1] 1 5 7 which(diff(c(x, 0L)) == -1L) #[1] 2 5 9 Otherwise you'd need something like x <- x == 1L first. Elegant way is y <- which(x==1) startIndx <- y[!(y-1) %in% y] stopIndex <- y[!(y+1) %in% y] rbind(startIndx, stopIndex)

OpenGL: Are VAOs and VBOs practical for large polygon rendering tasks?

六眼飞鱼酱① 提交于 2019-12-06 08:38:00
If you wanted to render a large landscape with thousands of polygons in the viewing frustum at a time as well as the user's viewpoint changing constantly, is it practical to use VAOs or VBOs? I mean, every time the player's position or camera rotation changed, you would have to recompute the vertex data in order to properly cull any vertices or scenes which are no longer seen in order to keep a good FPS count. But in doing this, your FPS count would go down because you are, well, repacking all the buffers constantly. So is it still beneficial to use these two methods over immediate mode? My

Fixing array indices in Python

不羁岁月 提交于 2019-12-06 07:22:06
I'd like to have arrays that start from say an index of 4 and go to 9. I'm not interested in creating memory space for < 4, so how is best to proceed? My 2D code is as follows: arr = [[ 0 for row in range(2)] for col in range(1, 129)] >>> arr[0][0] = 1 >>> arr[128][0] = 1 Traceback (most recent call last): File "<stdin>", line 1, in ? IndexError: list index out of range >>> arr[127][0] = 1 How can selectively just use the specific range i.e. where the last index runs from 1 to 128 inclusive not 0 to 127. This maybe obvious, but is there a way to do this? Thanks for the suggestion for dicts, I

python error : too many indices for array

我怕爱的太早我们不能终老 提交于 2019-12-06 04:14:43
My input was a csv file which was imported to postgresqldb .Later i am building a cnn using keras.My code below gives the following error "IndexError: too many indices for array". I am quite new to machine learning so I do not have any idea about how to solve this. Any suggestions? X = dataframe1[['Feature1','Feature2','Feature3','Feature4','Feature5','Feature6','Feature7','Feature8','Feature9','Feature10','Feature11\1','Feature12','Feature13','Feature14']] Y=result[['label']] # evaluate model with standardized dataset results = cross_val_score(estimator, X, Y, cv=kfold) print("Results: %.2f%%

BufferGeometry offsets and indices

独自空忆成欢 提交于 2019-12-05 16:53:48
I was just wondering for a while now what exactly "offsets" and "indices / index" are. Offsets are e.g. mentioned in https://github.com/mrdoob/three.js/blob/dev/src/core/BufferGeometry.js and indices were mentioned in IndexedGeometry, however I can't currently find it anymore in the dev tree. Although indices seem rather obvious and although I could dive into the code to figure out some maybe-correct answer for myself I'd love to hear an "official" statement :) Thanks! There are two ways to defining geometries: Non-Indexed "vertices": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ], "normals": [ 0, 1, 2, 3

Python: Delete all list indices meeting a certain condition

无人久伴 提交于 2019-12-05 15:50:52
to get right down to it, I'm trying to iterate through a list of coordinate pairs in python and delete all cases where one of the coordinates is negative. For example: in the array: map = [[-1, 2], [5, -3], [2, 3], [1, -1], [7, 1]] I want to remove all the pairs in which either coordinate is < 0, leaving: map = [[2, 3], [7, 1]] My problem is that python lists cannot have any gaps, so if I loop like this: i = 0 for pair in map: for coord in pair: if coord < 0: del map[i] i += 1 All the indices shift when the element is deleted, messing up the iteration and causing all sorts of problems. I've

Hard time understanding indices with glDrawElements

浪子不回头ぞ 提交于 2019-12-05 07:22:44
I'm trying to draw a terrain with GL_TRIANGLE_STRIP and glDrawElements but I'm having a really hard time understanding the indices thing behind glDrawElements ... Here's what I have so far: void Terrain::GenerateVertexBufferObjects(float ox, float oy, float oz) { float startWidth, startLength, *vArray; int vCount, vIndex = -1; // width = length = 256 startWidth = (width / 2.0f) - width; startLength = (length / 2.0f) - length; vCount = 3 * width * length; vArray = new float[vCount]; for(int z = 0; z < length; z++) { // vIndex == vIndex + width * 3 || width * 3 = 256 * 3 = 768 for(int x = 0; x <

Generate NumPy array containing the indices of another NumPy array

感情迁移 提交于 2019-12-04 05:06:53
问题 I'd like to generate a np.ndarray NumPy array for a given shape of another NumPy array. The former array should contain the corresponding indices for each cell of the latter array. Example 1 Let's say we have a = np.ones((3,)) which has a shape of (3,) . I'd expect [[0] [1] [2]] since there is a[0] , a[1] and a[2] in a which can be accessed by their indices 0 , 1 and 2 . Example 2 For a shape of (3, 2) like b = np.ones((3, 2)) there is already very much to write. I'd expect [[[0 0] [0 1]] [[1

Cumulative summation of a numpy array by index

江枫思渺然 提交于 2019-12-03 17:20:41
问题 Assume you have an array of values that will need to be summed together d = [1,1,1,1,1] and a second array specifying which elements need to be summed together i = [0,0,1,2,2] The result will be stored in a new array of size max(i)+1 . So for example i=[0,0,0,0,0] would be equivalent to summing all the elements of d and storing the result at position 0 of a new array of size 1 . I tried to implement this using c = zeros(max(i)+1) c[i] += d However, the += operation adds each element only once

What is the order of evaluation in python when using pop(), list[-1] and +=?

丶灬走出姿态 提交于 2019-12-03 10:29:29
问题 a = [1, 2, 3] a[-1] += a.pop() This results in [1, 6] . a = [1, 2, 3] a[0] += a.pop() This results in [4, 2] . What order of evaluation gives these two results? 回答1: RHS first and then LHS. And at any side, the evaluation order is left to right. a[-1] += a.pop() is same as, a[-1] = a[-1] + a.pop() a = [1,2,3] a[-1] = a[-1] + a.pop() # a = [1, 6] See how the behavior changes when we change the order of the operations at RHS, a = [1,2,3] a[-1] = a.pop() + a[-1] # a = [1, 5] 回答2: The key insight