I'm doing a project in one of my modules for college in C++ with SFML and I was hoping someone may be able to help me.
I'm using a vector of squares and triangles and I am using the SAT collision detection method to see if objects collide and to make the objects respond to the collision appropriately using the MTV(minimum translation vector)
Below…
Looking for a way to simulate nested loops (or a cartesian product) i came across the itertools.product function.
i need a function or piece of code that receive a list of integers as input and returns a specific generator.
example:
input = [3,2,4] - gen = product(xrange(3),xrange(2),xrange(4))
or
input = [2,4,5,6] - gen =…
I am trying to make my control lines static so instead of being displayed as part of the graph(the control lines are moving with the graph), they would be displayed like an axis
the app can only scroll horizontally
i'm talking about the two red line and the green line(which i put over the x axis)
this is how i do my…
Hello guys, I'm implement checkers (game) board with python. Here is how I switch it to the need structure
[8][8] array:
_matrix = []
for i in xrange(8):
_matrix.append( [' '] * 8 )
for row in xrange(0, 8):
for col in xrange(0, 8):
if _darkQuad(row, col) == True:
…
I'm trying to batch up a bunch of vertices and texture coords in an interleaved array before sending it to pyOpengl's glInterleavedArrays/glDrawArrays. The only problem is that I'm unable to find a suitably fast enough way to append data into a numpy array.
Is there a better way to do this? I would have…
Usual rules for the code golf. Here is an implementation in python as an example
from PIL import Image
im = Image.new("RGB", (300,300))
for i in xrange(300):
print "i = ",i
for j in xrange(300):
x0 = float( 4.0*float(i-150)/300.0 -1.0)
y0 = float( 4.0*float(j-150)/300.0 +0.0)
…
What is the rationale behind the advocated use of the for i in xrange(...)-style looping constructs in Python? For simple integer looping, the difference in overheads is substantial. I conducted a simple test using two pieces of code:
File idiomatic.py:
#!/usr/bin/env python
M = 10000
N = 10000
if…
I have the same code, written using win32com and xlrd. xlrd preforms the algorithm in less than a second, while win32com takes minutes.
Here is the win32com:
def makeDict(ws):
"""makes dict with key as header name,
value as tuple of column begin and column end (inclusive)"""
wsHeaders = {} # key…
Given an array of integers size N, how can you efficiently find a subset of size K with elements that are closest to each other?
Let the closeness for a subset (x1,x2,x3,..xk) be defined as:
2 <= N <= 10^5
2 <= K <= N
constraints: Array may contain duplicates and is not guaranteed…
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 11.
As always, any feedback is welcome.
# Euler 11
# http://projecteuler.net/index.php?section=problems&id=11
# What is the greatest product
# of four adjacent numbers in any…
I have been trying to debug this for hours. The program is supposed to be a grapher that graphs coordinates, but i cannot get anything to display not even a random line, but if i put a print statement there it works. It is a problem with the paintComponent Method. When I out print statement…
Problem Hey folks. I'm looking for some advice on python performance. Some background on my problem:
Given:
A mesh of nodes of size (x,y) each with a value (0...255) starting at 0
A list of N input coordinates each at a specified location within the range (0...x, 0...y)
Increment the…
I'm performing a nested loop in python that is included below. This serves as a basic way of searching through existing financial time series and looking for periods in the time series that match certain characteristics. In this case there are two separate, equally sized, arrays…
I have an issue in converting axis labels to int or float values.
This is my Y-Axis. It contains temperature values contains -50, 33, 117, 200.
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.orthogonalCoordinateDecimal =…
I'm working on a Python extension module, and one of my little test scripts is doing something strange, viz.:
x_max, y_max, z_max = m.size
for x in xrange(x_max):
for y in xrange(y_max):
for z in xrange(z_max):
#do my stuff
What makes no…
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 4.
As always, any feedback is welcome.
# Euler 4
# http://projecteuler.net/index.php?section=problems&id=4
# Find the largest palindrome made from…
Here is the code I was trying to turn into a list comprehension:
table = ''
for index in xrange(256):
if index in ords_to_keep:
table += chr(index)
else:
table += replace_with
Is there a way to add the else statement to this…
Hi there,
I currently encountered a problem:
I want to handle adding strings to other strings very efficiently, so I looked up many methods and techniques, and I figured the "fastest" method.
But I quite can not understand how it actually works:
def…
Some discussion in another question has encouraged me to to better understand cases where locking is required in multithreaded Python programs.
Per this article on threading in Python, I have several solid, testable examples of pitfalls that can…
I can't seem to get an animated transition between line graphs when I pass in a new set of data. I am using an array of objects as data like this:
[{
clicks: 40
installs: 10
time: "1349474400000"
},{
clicks: 61
…
I have implemented a naive merge sorting algorithm in Python. Algorithm and test code is below:
import time
import random
import matplotlib.pyplot as plt
import math
from collections import deque
def sort(unsorted):
if len(unsorted)…
I need to colour datapoints that are outside of the the confidence bands on the plot below differently from those within the bands. Should I add a separate column to my dataset to record whether the data points are within the confidence…
Hi,
I'm in a multimedia class in college, and we're "learning" OpenGL as part of the class. I'm trying to figure out how the OpenGL camera vs. modelview works, and so I found this example. I'm trying to port the example to Python using…
The following code runs too slowly even though everything seems to be vectorized.
from numpy import *
from scipy.sparse import *
n = 100000;
i = xrange(n); j = xrange(n);
data = ones(n);
A=csr_matrix((data,(i,j)));
x = A[i,j]
The…