Search Results

Search found 720 results on 29 pages for 'dimension'.

Page 18/29 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • Optimizing for speed - 4 dimensional array lookup in C

    - by Tiago
    I have a fitness function that is scoring the values on an int array based on data that lies on a 4D array. The profiler says this function is using 80% of CPU time (it needs to be called several million times). I can't seem to optimize it further (if it's even possible). Here is the function: unsigned int lookup_array[26][26][26][26]; /* lookup_array is a global variable */ unsigned int get_i_score(unsigned int *input) { register unsigned int i, score = 0; for(i = len - 3; i--; ) score += lookup_array[input[i]][input[i + 1]][input[i + 2]][input[i + 3]]; return(score) } I've tried to flatten the array to a single dimension but there was no improvement in performance. This is running on an IA32 CPU. Any CPU specific optimizations are also helpful. Thanks

    Read the article

  • How to add dimensions to dynamic img elements

    - by Mohammad
    I use a Json call to get a list of image addresses, then I add them individually to a div like this. <div id="container"> <img src="A.jpg" alt="" /> <img src="B.jpg" alt="" /> ... </div> Unfortunately the image dimension is not part of the Json information but I do need them for later JQuery DOM interactivity. Do any of you JQuery geniuses know of a code that would flawlessly add the width and height to the individual image elements in the container after they load? I was thinking maybe the code could wait for the images to have a width bigger than 5px then add the new width and height to the element. But I wouldn't know how to go about that and make it work stably. Thank you so much!

    Read the article

  • How to "smart resize" a displayed image to original aspect ratio

    - by Paul Sasik
    I have an application in which end-users can size and position images in a designer. Since the spec calls for the image to be "stretched" to the containing control, the end user can end up with an awkwardly stretched image. To help the user with image sizing I am thinking of implementing a smart resizer function which would allow the the user to easily fix the aspect ratio of the picture so that it no longer appears stretched. The quick way to solve this is to actually provide two options: 1) scale from width 2) scale from height. The user chooses the method and the algorithm adjusts the size of the picture by using the original aspect ratio. For example: A picture is displayed as 200x200 on the designer but the original image is 1024x768 pixels. The user chooses "Smart Size from width" and the new size becomes ~200x150 since the original aspect ratio is ~1.333 That's OK, but how could I make the algorithm smarter and not bother the user by asking which dimension the recalculation should be based on?

    Read the article

  • How do you get average of sums in SQL (multi-level aggregation)?

    - by paxdiablo
    I have a simplified table xx as follows: rdate date rtime time rid integer rsub integer rval integer primary key on (rdate,rtime,rid,rsub) and I want to get the average (across all times) of the sums (across all ids) of the values. By way of a sample table, I have (with consecutive identical values blanked out for readability): rdate rtime rid rsub rval ------------------------------------- 2010-01-01 00.00.00 1 1 10 2 20 2 1 30 2 40 01.00.00 1 1 50 2 60 2 1 70 2 80 02.00.00 1 1 90 2 100 2010-01-02 00.00.00 1 1 999 I can get the sums I want with: select rdate,rtime,rid, sum(rval) as rsum from xx where rdate = '2010-06-01' group by rdate,rtime,rid which gives me: rdate rtime rid rsum ------------------------------- 2010-01-01 00.00.00 1 30 (10+20) 2 70 (30+40) 01.00.00 1 110 (50+60) 2 150 (70+80) 02.00.00 1 190 (90+100) as expected. Now what I want is the query that will also average those values across the time dimension, giving me: rdate rtime ravgsum ---------------------------- 2010-01-01 00.00.00 50 ((30+70)/2) 01.00.00 130 ((110+150)/2) 02.00.00 190 ((190)/1) I'm using DB2 for z/OS but I'd prefer standard SQL if possible.

    Read the article

  • JavaFX layouts question.

    - by Jhonghee
    I am having some problem understanding layouts in JavaFX. Consider following code. Stage { title: "ListView test" scene: Scene { width: 400 height: 400 content: [ VBox { content: [ ListView { height: 200 width: 200 items: ["item1", "item2"] } ] } ] } } I was expecting ListView showing up in 200 x 200 dimension but no matter how I tried to fix this, the width and height of ListView seemed fixed. But following code works for showing ListView as I intended. Stage { title: "ListView test" scene: Scene { width: 400 height: 400 content: [ ListView { height: 200 width: 200 items: ["item1", "item2"] } ] } } So, what is the problem here? I cannot use ListView within layouts?

    Read the article

  • Cropping image with ImageScience

    - by fl00r
    ImageScience is cool and light. I am using it in my sinatra app. But I can't understand how can I crop image with not square form and how can I make thumbnail with two dimensions. As I found on ImageScience site: ImageScience.with_image(file) do |img| img.cropped_thumbnail(100) do |thumb| thumb.save "#{file}_cropped.png" end img.thumbnail(100) do |thumb| thumb.save "#{file}_thumb.png" end img.resize(100, 150) do |img2| img2.save "#{file}_resize.png" end end I can crop thumb and resize thumb only with ONE dimension but I want to use two, as in RMagick. For example I want to crop 100x200px box from image, or I want to make thumbnail with width or height not bigger then 300 (width) or 500 (height) pixels.

    Read the article

  • Why cant i draw an elipse in with code?

    - by bvivek88
    package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class test_bmp extends JPanel implements MouseListener,MouseMotionListener,ActionListener { static BufferedImage image; Color color; Point start=new Point(); Point end =new Point(); JButton elipse=new JButton("Elipse"); JButton rectangle=new JButton("Rectangle"); JButton line=new JButton("Line"); String selected; public test_bmp() { color = Color.black; setBorder(BorderFactory.createLineBorder(Color.black)); addMouseListener(this); addMouseMotionListener(this); } public void paintComponent(Graphics g) { //super.paintComponent(g); g.drawImage(image, 0, 0, this); Graphics2D g2 = (Graphics2D)g; g2.setPaint(Color.black); if(selected=="elipse") { g2.drawOval(start.x, start.y, (end.x-start.x),(end.y-start.y)); System.out.println("Start : "+start.x+","+start.y); System.out.println("End : "+end.x+","+end.y); } if(selected=="line") g2.drawLine(start.x,start.y,end.x,end.y); } //Draw on Buffered image public void draw() { Graphics2D g2 = image.createGraphics(); g2.setPaint(color); System.out.println("draw"); if(selected=="line") g2.drawLine(start.x, start.y, end.x, end.y); if(selected=="elipse") { g2.drawOval(start.x, start.y, (end.x-start.x),(end.y-start.y)); System.out.println("Start : "+start.x+","+start.y); System.out.println("End : "+end.x+","+end.y); } repaint(); g2.dispose(); } public JPanel addButtons() { JPanel buttonpanel=new JPanel(); buttonpanel.setBackground(color.lightGray); buttonpanel.setLayout(new BoxLayout(buttonpanel,BoxLayout.Y_AXIS)); elipse.addActionListener(this); rectangle.addActionListener(this); line.addActionListener(this); buttonpanel.add(elipse); buttonpanel.add(Box.createRigidArea(new Dimension(15,15))); buttonpanel.add(rectangle); buttonpanel.add(Box.createRigidArea(new Dimension(15,15))); buttonpanel.add(line); return buttonpanel; } public static void main(String args[]) { test_bmp application=new test_bmp(); //Main window JFrame frame=new JFrame("Whiteboard"); frame.setLayout(new BorderLayout()); frame.add(application.addButtons(),BorderLayout.WEST); frame.add(application); //size of the window frame.setSize(600,400); frame.setLocation(0,0); frame.setVisible(true); int w = frame.getWidth(); int h = frame.getHeight(); image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setPaint(Color.white); g2.fillRect(0,0,w,h); g2.dispose(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } @Override public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent event) { start = event.getPoint(); } @Override public void mouseReleased(MouseEvent event) { end = event.getPoint(); draw(); } @Override public void mouseDragged(MouseEvent e) { end=e.getPoint(); repaint(); } @Override public void mouseMoved(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==elipse) selected="elipse"; if(e.getSource()==line) selected="line"; draw(); } } I need to create a paint application, when i draw elipse by dragging mouse from left to right it displays nothing, why?? should i use any other function here?

    Read the article

  • NumPy: how to quickly normalize many vectors?

    - by EOL
    How can a list of vectors be elegantly normalized, in NumPy? Here is an example that does not work: from numpy import * vectors = array([arange(10), arange(10)]) # All x's, then all y's norms = apply_along_axis(linalg.norm, 0, vectors) # Now, what I was expecting would work: print vectors.T / norms # vectors.T has 10 elements, as does norms, but this does not work The last operation yields "shape mismatch: objects cannot be broadcast to a single shape". How can the normalization of the 2D vectors in vectors be elegantly done, with NumPy? Edit: Why does the above not work while adding a dimension to norms does work (as per my answer below)?

    Read the article

  • Understanding OpenGL Matrices

    - by Omega
    I'm starting to learn about 3D rendering and I've been making good progress. I've picked up a lot regarding matrices and the general operations that can be performed on them. One thing I'm still not quite following is OpenGL's use of matrices. I see this (and things like it) quite a lot: x y z n ------- 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 So my best understanding, is that it is a normalized (no magnitude) 4 dimensional, column-major matrix. Also that this matrix in particular is called the "identity matrix". Some questions: What is the "nth" dimension? How and when are these applied? My biggest confusion arises from how OpenGL makes use of this kind of data.

    Read the article

  • how do i see if a big JSON object contains a value?

    - by Haroldo
    I'm using PHP to json encode a massive multi-dimensional array of events, so i get something like this: var ents = {"7":{"event_id":"7","nn":"The Whisky Drifters","nn_url":"the-whisky-drifters","venue":"The Grain Barge","date_num":"2010-06-11","date_txt":"Friday 11th June","gig_club":"1","sd":"A New Acoustic String Band...","ven_id":"44","art":0},"15":{"event_id":"15","nn":"Bass Kitchen","nn_url":"bass-kitchen","venue":"Timbuk2","date_num":"2010-06-11","date_txt":"Friday 11th June","gig_club":"2","sd":"Hexadecimal \/ DJ Derek \/ Id","ven_id":"21","art":1}, the first dimension is the id, see var ents = {"7":{ So its possible to get the ids without examining the nested objects... What's the fastest, most efficent way to check if my JSON contains an id?

    Read the article

  • Many-To-Many dimensional model

    - by Mevdiven
    Folks, I have a dimension table called DIM_FILE which holds information of the files we received from customers. Each file has detail records which constitutes my FACT table, CUST_DETAIL. In the main process, file is gone through several stages and each stage tags a status to it. Long in a short, I have many-to-many relationship. Any ideas around star schema dimensional modeling. A customer record only belong to a single file and a file can have multiple statuses. FACT ---- CustID FileID AmountDue DIM_FILE -------- FileID FileName DateReceived FILE_STATUS ----------- FileID StatusDateTime StatusCode

    Read the article

  • MDX query for SSRS2008 parameter, to be used as filter in dataset

    - by adolf garlic - SAVE BBC6MUSIC
    What I want to do: The report parameter that the user can select from is a subset of the data available in a dimension. I have a query to retrieve this subset and it works fine. I am then trying to use the selection as a filter in a dataset. In the dataset properties, you can add a parameter based on the ones you have specified on the report, but when you look in the filters pane, there seems to be no way to select this. If I try and select something in there, it creates a whole new parameter and dataset. How can I get a dataset to consume and filter by a parameter that the user has selected?

    Read the article

  • Using GLOrtho to view Side, Front, Top perspectives of a 3D scene

    - by talldan
    Dear all, I'm building a game level editing app as part of a university project. In my application I have multiple viewports, a Perspective viewport and three orthographic views all setup to view the same scene. I've successfuly setup the orthographic views and can translate and scale them to mimic scrolling and zooming. Unfortunately, I'm having one problem - my scene still contains 3 dimensions, so objects viewed in orthographic mode of certain depths are clipped when they fall outside of my clipping volume. Most 3D authoring tools or level editors allow you to view all objects in orthographic mode regardless of depth. I guess what I need to do is scale my scene in the appropriate dimension so that all values lie between 1 and -1, is there a straightforward way of going about this? Or is there a different better approach. Thanks very much for your help, Dan

    Read the article

  • extend web server to serve static files

    - by Turtle
    Hello, I want to extend a web server which is only able to handle RPC handling now. The web server is written in C#. It provides a abstract handler function like following: public string owsHandler(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse) And I wrote following code to handle image files: Bitmap queryImg = new Bitmap(path); System.IO.MemoryStream stream = new System.IO.MemoryStream(); queryImg.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); queryImg.Dispose(); byte[] byteImage = stream.ToArray(); stream.Dispose(); return Convert.ToBase64String(byteImage); And I test it in the browser, the image is returned but the image dimension info is missed. Shall I add something more to the code? Or is any general way to server static files? I do not want to serve it in a ASP.net server. Thanks

    Read the article

  • vectorized approach to binning with numpy/scipy in Python

    - by user248237
    I am binning a 2d array (x by y) in Python into the bins of its x value (given in "bins"), using np.digitize: elements_to_bins = digitize(vals, bins) where "vals" is a 2d array, i.e.: vals = array([[1, v1], [2, v2], ...]). elements_to_bins just says what bin each element falls into. What I then want to do is get a list whose length is the number of bins in "bins", and each element returns the y-dimension of "vals" that falls into that bin. I do it this way right now: points_by_bins = [] for curr_bin in range(min(elements_to_bins), max(elements_to_bins) + 1): curr_indx = where(elements_to_bins == curr_bin)[0] curr_bin_vals = vals[:, curr_indx] points_by_bins.append(curr_bin_vals) is there a more elegant/simpler way to do this? All I need is a list of of lists of the y-values that fall into each bin. thanks.

    Read the article

  • Query regarding the Nhibernate many to many mapping

    - by Pramod
    Hi, I have a requirement where i have 3 dimension tables (employee, project, technology) and a common fact table which has the key id's of all these three tables. My question goes like this... How do i create a mapping table (fact table) having these three columns - emp_id, proj_i and tech_i. I know we can achieve this for two tables using the below syntax: HasManyToMany(x = x.Empl) .Table("Emp_Proj") .ParentKeyColumn("Emp_i") .ChildKeyColumn("Proj_I") .Inverse() .Cascade.All(); How can i add another child key column (tech_i) to the above mapping table?

    Read the article

  • Math/numerical formula every computer programmer should know

    - by aaa
    This is a follow-up question to What should every programmer know and Is mathematics necessary. So the question is, as a computer programmer, what is the most important/useful mathematical or numerical formula that you use? By Formula I mean anything that involves less obvious manipulations, whenever binomial coefficients or bit hacks. I work with multidimensional arrays and various matrix representations. So for me most commonly used formulas are: A(i,j,k,..) = a[i + j*Dim0 + k*Dim0*Dim1 + ... to map indexes to one dimension ( which is basic address calculation which many people do not seem to know). And triangular number T(i) = (i*i + i)/2 which is related to binomial coefficients, used to calculate address in triangular matrixes and many other things. What is your workhorse formula that you think programmer should know?

    Read the article

  • Cross browser div alignment using CSS

    - by Misha Moroshko
    What is the easiest way to align a div whose position is relative horizontally and vertically using CSS ? The width and the height of the div is unknown, i.e. it should work for every div dimension and in all major browsers. I thought to make the horizontal alignment using: margin-left: auto; margin-right: auto; like I did here. Is this a good cross browser solution for horizontal alignment ? How could I do the vertical alignment ?

    Read the article

  • MDX: How To Aggregate Hierarchy Level Members With Same Name

    - by Dave Frautnick
    Greetings, I am new to MDX, and am having trouble understanding how to perform an aggregation on a hierarchy level with members that have the same names. This query is particular to Microsoft Analysis Services 2000 cubes. I have a given hierarchy dimension with levels defined as follows: [Segment].[Flow].[Segment Week] Within the [Segment Week] level, I have the following members: [Week- 1] [Week- 2] [Week- 3] ... [Week- 1] [Week- 2] [Week- 3] The members have the same names, but are aligned with a different [Flow] in the parent level. So, the first occurrence of the [Week- 1] member aligns with [Flow].[A] while the second occurrence of [Week- 1] aligns with [Flow].[B]. What I am trying to do is aggregate all the members within the [Segment Week] level that have the same name. In SQL terms, I want to GROUP BY the member names within the [Segment Week] level. I am unsure how to do this. Thank you. Dave

    Read the article

  • How to remove the title bar from a JFrame screenshot?

    - by Greg Harman
    I'm capturing a screenshot image of a JFrame via a "double buffering" approach, per below: public BufferedImage getScreenshot() { java.awt.Dimension dim = this.getPreferredSize(); BufferedImage image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); this.paint(image.getGraphics()); return image; } where this extends JFrame. The image that I get has a blank strip along the top where the title bar was. What's the most straightforward way to capture an image of the contents of the JFrame without the extra space allocated for the title bar?

    Read the article

  • I'm having a hard time calling the variable from first frame.

    - by iownfloppydisk
    here is how should my program be. In first frame, there is a textfield1 where a user input text and when he press a button, a new frame will be display with a textfield2 that displays the inputted text from the textfield1. please help me with the syntax. i'm still a beginner in java. much thanks guys. First Frame: textfield= new JTextField(); textfield.setPreferredSize( new Dimension(200,30) ) ; textfield.setSize( textfield.getPreferredSize() ) ; textfield.setLocation(95,198) ; textfield.setSize(175,28); cont.add(textfield); public void actionPerformed(ActionEvent e) { this.setVisible(false); new Frame2().setVisible(true); //displays the 2nd frame right? } now i don't know what to do on my 2nd frame or where to start because i can't get the variable from the first frame

    Read the article

  • Python - How to find a correlation between two vectors ?

    - by psihodelia
    Given two vectors X and Y I have to find their correlation, i.e. their linear dependence/independence. Both vectors have equal dimension. A resulted answer should be a floating point number from [-1.0 .. 1.0]. Example: X=[-1, 2, 0] Y=[ 4, 2, -0.3] Find y=cor(X,Y) such that y belongs to [-1.0 .. 1.0]. It should be a simple construction involving a list-comprehension. No external library is allowed. UPDATE: ok, if dot product is enough, then here is my solution: nX = 1/(sum([x*x for x in X]) ** 0.5) nY = 1/(sum([y*y for y in Y]) ** 0.5) cor = sum([(x*nX)*(y*nY) for x,y in zip(X,Y) ]) right?

    Read the article

  • Add a listener inside or outside get method

    - by James P.
    I'm learning Swing and have composed an interface using a series of get methods to add components. Is it a good practise to add a Listener inside a get method as follows? I'd like to make things as decoupled as possible. private JButton getConnectButton() { if (connectButton == null) { connectButton = new JButton(); connectButton.setText("Connect"); connectButton.setSize(new Dimension(81, 16)); connectButton.setLocation(new Point(410, 5)); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // actionPerformed code goes here } }); } return connectButton; }

    Read the article

  • create a sparse BufferedImage in java

    - by elgcom
    I have to create an image with very large resolution, but the image is relatively "sparse", only some areas in the image need to draw. For example with following code /* this take 5GB memory */ final BufferedImage img = new BufferedImage( 36000, 36000, BufferedImage.TYPE_INT_ARGB); /* draw something */ Graphics g = img.getGraphics(); g.drawImage(....); /* output as PNG */ final File out = new File("out.png"); ImageIO.write(img, "png", out); The PNG image on the end I created is ONLY about 200~300 MB. The question is how can I avoid creating a 5GB BufferedImage at the beginning? I do need an image with large dimension, but with very sparse color information. Is there any Stream for BufferedImage so that it will not take so much memory?

    Read the article

  • Loading Fact Table + Lookup / UnionAll for SK lookups.

    - by Nev_Rahd
    I got to populate FactTable with 12 lookups to dimension table to get SK's, of which 6 are to different Dim Tables and rest 6 are lookup to same DimTable (type II) doing lookup to same natural key. Ex: PrimeObjectID = lookup to DimObject.ObjectID = get ObjectSK and got other columns which does same OtherObjectID1 = lookup to DimObject.ObjectID = get ObjectSK OtherObjectID2 = lookup to DimObject.ObjectID = get ObjectSK OtherObjectID3 = lookup to DimObject.ObjectID = get ObjectSK OtherObjectID4 = lookup to DimObject.ObjectID = get ObjectSK OtherObjectID5 = lookup to DimObject.ObjectID = get ObjectSK for such multiple lookup how should go in my SSIS package. for now am using lookup / unionall foreach lookup. Is there a better way to this.

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >