2d

How to append to a 2d slice

流过昼夜 提交于 2021-01-29 16:14:01
问题 I have data that is created rows by rows, 6 columns, I don't know the final number of rows in advance. Currently i'm creating a 2D slice of 200x6 with all zeros and then i replace these zeros gradually with my data, row by row. The data comes from another dataframe df It works but i don't like to end up with the last rows of my slice full of zeros. I see 2 solutions: - I delete all the last rows with only zeros when I'm done - I create an empty slice and append my data progressively to it I

How to pick a random element in a 2 dimensional array

空扰寡人 提交于 2021-01-29 15:42:16
问题 Ok I want to pick a random point in the 2d array so it can be filled. Ive seen how to do this for a 1d array, and am wondering how this would be possible in a 2d array. All I have seen about this method is that the same position comes up again, which is a slight problem, but I don't know how to do it in the first place. The 2d array is essentially a grid, with the dimensions being the x and y coordinates. And the random element selecting a point within the boundaries (which is user selected

How can i make the enemy go to the character position?

微笑、不失礼 提交于 2021-01-29 07:50:56
问题 What my game has is a character in a preset position in a 2d-game mobile(x=0.33, y=9.48, z=0). I have enemys that are spawn from different angles of the screen with a movement script. But i have to modify the script so it moves towards the character position always. Tried to set the position of the enemy = with character position. but that doesnt work. Anyone has any idea how can i do that? here is the script: /// //Speed - essential : true ? let speed; let enabled = false; let phys; function

Check value of neighbouring squares in 2D array

你离开我真会死。 提交于 2021-01-29 07:27:32
问题 I am creating a simple mine-sweeper board with 2D array. I wants to populate the squares surrounding the "Bomb(s)" with respective numbers. I don't need to care whether the board I created can be solved. (Not important here) My question is: How can we populate the numbers elegantly without listing out all the possibilities as if we were hard-coding? What I came out with for now is a massive nested if-statements to check whether the neighbour is -Inside bounds of array -Is it a bomb -Is it

How do I find the Pareto-optimal points in O(nh) and O(nlog(h)) complexity?

心已入冬 提交于 2021-01-29 04:00:37
问题 Can anybody suggest an algorithm to find Pareto-optimal points (to form a staircase) just as given in diagram in O(n*h) and O(n*log(h)) time complexity, where h is the number of Pareto-optimal points? I used gift wrapping algorithm to solve this (in O(n*h) ), but it only finds convex hulls type of staircase and misses those points who form concave angles. 回答1: To put suggestion in one place. Idea is to use divide and conquer strategy. If we can find pareto point P which splits rest of pareto

How to transpose a 2D list array using loops in python?

此生再无相见时 提交于 2021-01-28 21:50:49
问题 Say I have: a = [[1, 1, 1, 6], [0, 2, -1, 3], [4, 0, 10, 42]] and I want to transpose it to: a = [[1,0,4], [1,2,0], [1,-1,10], [6,3,42]] using loops in python. The current code that I have is: def transpose(a): s = [] for row in range(len(a)): for col in range(len(a)): s = s + [a[col][row]] return s But this gives me the output of: [1, 0, 4, 1, 2, 0, 1, -1, 10] Instead of this: [[1,0,4], [1,2,0], [1,-1,10], [6,3,42]] Can anyone help me? I'm still new at this stuff and don't understand why it

How to transpose a 2D list array using loops in python?

大兔子大兔子 提交于 2021-01-28 21:06:58
问题 Say I have: a = [[1, 1, 1, 6], [0, 2, -1, 3], [4, 0, 10, 42]] and I want to transpose it to: a = [[1,0,4], [1,2,0], [1,-1,10], [6,3,42]] using loops in python. The current code that I have is: def transpose(a): s = [] for row in range(len(a)): for col in range(len(a)): s = s + [a[col][row]] return s But this gives me the output of: [1, 0, 4, 1, 2, 0, 1, -1, 10] Instead of this: [[1,0,4], [1,2,0], [1,-1,10], [6,3,42]] Can anyone help me? I'm still new at this stuff and don't understand why it

Assigning a 2D image for every face of a 3D cube: MATLAB

泄露秘密 提交于 2021-01-28 20:41:36
问题 I want to build a cube in MATLAB and assign different 2D images for its faces. I think this is called texture mapping. I've searched for such a code, but what I found is a code that is able to assign a single image to all of the cube faces, the code is available here (http://www.mathworks.com/matlabcentral/answers/32070-rgb-images-on-a-3d-cube). Here is the code, cdata = flipdim( imread('peppers.png'), 1 ); cdatar = flipdim( cdata, 2 ); % bottom surface([-1 1; -1 1], [-1 -1; 1 1], [-1 -1; -1

Assigning a 2D image for every face of a 3D cube: MATLAB

為{幸葍}努か 提交于 2021-01-28 19:25:19
问题 I want to build a cube in MATLAB and assign different 2D images for its faces. I think this is called texture mapping. I've searched for such a code, but what I found is a code that is able to assign a single image to all of the cube faces, the code is available here (http://www.mathworks.com/matlabcentral/answers/32070-rgb-images-on-a-3d-cube). Here is the code, cdata = flipdim( imread('peppers.png'), 1 ); cdatar = flipdim( cdata, 2 ); % bottom surface([-1 1; -1 1], [-1 -1; 1 1], [-1 -1; -1

How to create 3D tile maps using a Plane object divided into tiles?

大城市里の小女人 提交于 2021-01-28 17:53:15
问题 I want to create a 2D plane centered on 0,0,0 in 3D world space. Then, I want to define this plane in 2d tile coordinates. So e.g. a plane divided by 3 tiles would become a map of an array [3,3] The issue is that this would still give a tilemap with negative points. The world upper left -1,1 would be 0,0 in the array -1,- would be 1,0 and so on... World: -1,1 0,1 1,1 -1,0 0,0 1,0 -1,-1 0,-1 1,-1 Array: 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 My main hope with Unity was that I could avoid the math