2d

How can i make a 2D array with existing lists?

谁都会走 提交于 2019-12-02 07:59:40
for instance, i have a txt data called 'mazeline' like this: abcd cdae korp So i first made 3 lists: mazeline = readmaze.split() mline0 = list(mazeline[0]) mline1 = list(mazeline[1]) mline2 = list(mazeline[2]) So the 3 lists are: mline0 = [a,b,c,d] mline1 = [c,d,a,e] mline2 = [k,o,r,p] and i want to make a 2D array like this: [[a,b,c,d],[c,d,a,e],[k,o,r,p]] or is there any way that i can make a 2d array directly from the first data? any suggestions? any help would be good. Just put the lists inside another list res = [mline0, mline1, mline2] more simply, you can skip the intermediate variables

convert an 2d array from rows to blocks

为君一笑 提交于 2019-12-02 07:20:25
I am trying to work in this code for weeks. I need to convert rows and columns in a 2d array to blocks. it should work on any matrix in size n*n. (that I have been given the size of the array) for example: this: int[][] input = {{1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}} ; this is need to be the output: {{1,2,3,1,2,3,1,2,3} {4,5,6,4,5,6,4,5,6} {7,8,9,7,8,9,7,8,9} {1,2,3,1,2,3,1,2,3} {4,5,6,4,5,6,4,5,6} {7,8,9,7,8,9,7,8,9} {1,2,3,1,2,3,1,2,3} {4,5,6,4

Perspective transform with WPF

寵の児 提交于 2019-12-02 07:13:06
WPF allows to specify linear affine transform on graphical objects. With this you can do translation, rotation, scaling, skewing, or a combination of that. You can specify a 2x3 matrix. What I want to do is a perspective transform in 2D space, which requires a 3x3 matrix, and is known from Photoshop or GIMP, where you can drag all 4 corners of an image independently. I tried to use the 3D features of WPF, set up a Viewport3D , an OrthographicCamera and placed the (2D) objects onto the xy-plane. But I'm wondering if there is no easier way to accomplish the perspective transform in WPF? I'm

Order / Sequence of matrix transformations in 2D

ぐ巨炮叔叔 提交于 2019-12-02 07:08:29
I have an image containing: a set of coordinates that act as orientation markers. a set of coordinates containing data. Let's call this image A. This image is fed to a scanner that returns a copy of the image with certain transformations applied (rotation, scale, translation). Let's call the transformed image B. The transformation values applied are not know to me, of course. Once I receive the transformed image (B), I can easily track the coordinates of the orientation markers and calculate the angle of rotation, scale (x,y) and translation (x,y). Now I need to retrieve the data coordinates

Finding valid neighbors in 2D array

微笑、不失礼 提交于 2019-12-02 06:58:48
So, I have a 4x4 2D array (it will always be these dimensions). Starting with a location on the array, some row and column, I want to find all of its valid neighbors. So far, I have a really clunky implementation. //add row if ( !((row + 1) > 3)) { //do stuff } //sub row if ( !((row - 1) < 0)) { //do stuff } //add col if ( !((col + 1) > 3)) { //do stuff } //sub col if ( !((col - 1) < 0)) { //do stuff } ... and so on This is brutal. I feel like I do not need to check every single neighbor when I start by knowing the location of the element. Any ideas? Jayant Narwani For any 2D array cellValues[

OpenGL GLSL Binding Sampler for Fragment Shader

不想你离开。 提交于 2019-12-02 06:34:10
I am hoping to implement a shader on a 2D OpenGL application. My plan is to render a scene to a framebuffer object, and then render that framebuffer object to the screen using a shader. Here is the scene, which I have drawn to a framebuffer object, and then to the screen from there. Using the arrow keys makes the moon move around (I am quite proud of it!) However, when I try to render the framebuffer object to the screen using my shader program, I get this: It is very sad. This fragment shader is one which I got from a tutorial , and I'm sure the problem has to be with the Uniform Variables.

How do I get this 2D Array to rotate to the right 90 degrees?

柔情痞子 提交于 2019-12-02 06:26:10
问题 So I have a 2D array, and it is supposed to rotate to the right 90 degrees, but instead it rotates to the left. Really can't figure out why public class CrackCode16 { public static void main (String args[]){ int [] [] oldarray = new int [3][3]; int value = 1; for (int i = 0; i < 3; i++){ for (int j =0; j<3; j++){ oldarray[i][j] = value; value++; } } for (int i = 0; i < 3; i++){ for (int j =0; j<3; j++){ System.out.print(oldarray[i][j] + "\t"); } System.out.println(""); } oldarray = rotate

OnTriggerEnter not working

和自甴很熟 提交于 2019-12-02 05:20:31
public var enemy:GameObject; enemy = GameObject.FindGameObjectWithTag("enemy"); function OnTriggerEnter(other:Collider) { if(other.gameObject.tag == "enemy") { Debug.Log("Dead"); Destroy(gameObject); } } This script is attached to a prefab arrow that gets instantiated. The enemy has a circle collider and the arrow has a box collider. The arrow has on IsTrigger checked. What have I done wrong? Both gameobjects have a rigidbobdy2D attached. If you use the 2D physics engine, you need to use the 2D functions: function OnTriggerEnter2D(other: Collider2D) { if(other.tag == "enemy") { Debug.Log("Dead

Get user input as int or str

时光怂恿深爱的人放手 提交于 2019-12-02 05:13:47
I'm very new to python and believe me, I've searched endlessly for a solution to this but I just can't get it. I have a csv with a list of monitoring plots. With the code below, I have been able to display the 2dlist and get the user to enter a number to choose a particular plot (there's 11 of them), based on the list index. But when prompting the user to choose, I'd like to include an option '....or press 'q' to quit'. Now obviously raw_input is set to receive integers only but how can I accept a number from the list or 'q'? If I remove 'int' from raw_ input, it keeps prompting to enter again

c++ passing 2d arrays to funcions

元气小坏坏 提交于 2019-12-02 04:16:14
I know my code isnt finished yet im not asking for it to be done. It's supposed to input food eaten by 3 monkeys over a week and other stuff. But I've hit a snag. It gives me an error(Error: no operator "<<" matches these operands) when i put the cin in the poundsEaten function. Am I not passing the array right is that why it isnt working? Thanks for any help #include <iomanip> #include <iostream> using namespace std; //Global Constants const int NUM_MONKEYS = 3; const int DAYS = 7; //Prototypes void poundsEaten(const double[][DAYS],int, int); void averageEaten(); void least(); void most();