indices

Connecting Sphere Vertices OpenGL

丶灬走出姿态 提交于 2019-12-24 15:59:58
问题 I am trying to render a sphere in OpenGL using GL_TRIANGLES. Here is an image of what I am getting with the code below.. Bad Sphere This is supposed to be a unit sphere. I have derived the vertices from the basic sphere approximations from wikipedia. Here is the code that I created to render the unit sphere.. Please let me know where I am going wrong void createGreenSphere(mat4 modelView){ std::vector< Vertex > v; int numSphereSlices = 12; int numSphereSegments = 12; float theta = 0; float

How to get row, column indices of all non-NaN items in Pandas dataframe

随声附和 提交于 2019-12-24 15:58:23
问题 How do I iterate over a dataframe like the following and return the non-NaN value locations as a tuple. i.e. df: 0 1 2 0 NaN NaN 1 1 1 NaN NaN 2 NaN 2 NaN I would get an output of [(0, 1), (2, 0), (1, 2)]. Would the best way be to do a nested-for loop? Or is there an easier way I'm unaware of through Pandas. 回答1: Assuming you don't need in order, you could stack the nonnull values and work on index values. In [26]: list(df[df.notnull()].stack().index) Out[26]: [(0L, '2'), (1L, '0'), (2L, '1')

numpy 2D array: get indices of all entries that are connected and share the same value

拟墨画扇 提交于 2019-12-24 05:05:34
问题 I have a 2D numpy Array filled with integer-values from 0 to N, how can i get the indices of all entries that are directly connected and share the same value. Addition: Most of the entries are zero and can be ignored! Example Input array: [ 0 0 0 0 0 ] [ 1 1 0 1 1 ] [ 0 1 0 1 1 ] [ 1 0 0 0 0 ] [ 2 2 2 2 2 ] Wished output indices: 1: [ [1 0] [1 1] [2 1] [3 0] ] # first 1 cluster [ [1 3] [1 4] [2 3] [2 4] ] # second 1 cluster 2: [ [4 0] [4 1] [4 2] [4 3] [4 4] ] # only 2 cluster the formating

numpy 2D array: get indices of all entries that are connected and share the same value

妖精的绣舞 提交于 2019-12-24 05:05:03
问题 I have a 2D numpy Array filled with integer-values from 0 to N, how can i get the indices of all entries that are directly connected and share the same value. Addition: Most of the entries are zero and can be ignored! Example Input array: [ 0 0 0 0 0 ] [ 1 1 0 1 1 ] [ 0 1 0 1 1 ] [ 1 0 0 0 0 ] [ 2 2 2 2 2 ] Wished output indices: 1: [ [1 0] [1 1] [2 1] [3 0] ] # first 1 cluster [ [1 3] [1 4] [2 3] [2 4] ] # second 1 cluster 2: [ [4 0] [4 1] [4 2] [4 3] [4 4] ] # only 2 cluster the formating

Fixing array indices in Python

戏子无情 提交于 2019-12-23 00:25:18
问题 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

Python: split list of integers based on step between them

Deadly 提交于 2019-12-22 06:59:38
问题 I have the following problem. Having a list of integers, I want to split it, into a list of lists, whenever the step between two elements of the original input list is not 1. For example: input = [0, 1, 3, 5, 6, 7], output = [[0, 1], [3], [5, 6, 7]] I wrote the following function, but it's uggly as hell, and I was wondering if anyone of you guys would help me get a nicer solution. I tried to use itertools, but couldn't solve it. Here's my solution: def _get_parts(list_of_indices): lv = list

Hard time understanding indices with glDrawElements

寵の児 提交于 2019-12-22 05:10:23
问题 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

reset_index() to original column indices after pandas groupby()?

∥☆過路亽.° 提交于 2019-12-21 19:58:18
问题 I generate a grouped dataframe df = df.groupby(['X','Y']).max() which I then want to write (to csv, without indexes). So I need to convert 'X' and 'Y' back to regular columns; I tried using reset_index() , but the order of columns was wrong. How to restore columns 'X' and 'Y' to their exact original column position? Is the solution: df.reset_index(level=0, inplace=True) and then find a way to change the order of the columns? (I also found this approach, for multiindex) 回答1: This solution

indices of the k largest elements in an unsorted length n array

非 Y 不嫁゛ 提交于 2019-12-20 09:14:31
问题 I need to find the indices of the k largest elements of an unsorted, length n, array/vector in C++, with k < n. I have seen how to use nth_element() to find the k-th statistic, but I'm not sure if using this is the right choice for my problem as it seems like I would need to make k calls to nth_statistic, which I guess it would have complexity O(kn), which may be as good as it can get? Or is there a way to do this just in O(n)? Implementing it without nth_element() seems like I will have to

Access entries in pandas data frame using a list of indices

走远了吗. 提交于 2019-12-19 09:45:13
问题 I facing the issue that I need only a subset of a my original dataframe that is distributed over different rows and columns. E.g.: # My Original dataframe import pandas as pd dfTest = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9]]) Output: 0 1 2 0 1 2 3 1 4 5 6 2 7 8 9 I can provide a list with rows and column indices where my desired values are located: array_indices = [[0,2],[1,0],[2,1]] My desired output is a series: 3 4 8 Can anyone help? 回答1: Use pd.DataFrame.lookup dfTest.lookup(*zip(*array