14,946 Topics

Member Avatar for
Member Avatar for Michael_Levin

hello! can you please help me with fast numpy transform. i have qimage (argb32) converted to numpy, so it's now an array of shape (128,128,4). and i want the fastest way to convert it to grayscale - the formula is (pseudocode): [CODE]lerp(PIX, dot(PIX, (0.299, 0.587, 0.114)), alpha)[/CODE] where PIX - …

Member Avatar for TrustyTony
0
182
Member Avatar for HoneyBadger

I am trying to add two hexadecimal numbers. [CODE]def addbinary(n1,n2): s = "" carry = '0' for i in range(3,-1,-1): if (n1[i] == '1' and n2[i] == '1' and carry == '0'): s = '0' + s carry = '1' elif (n1[i] == '1' and n2[i] == '1' and carry …

Member Avatar for HoneyBadger
0
338
Member Avatar for TrustyTony

This handy function turns file into stream of words stripped of punctuation, whitespace and digits, but does not split for example we'd to two words. If you want that you can further process yielded words or change the definition.

Member Avatar for griswolf
3
2K
Member Avatar for Asset

def getAverage(numList): total = 0 for i in range(0, len(numList)): total = float(numList[i]) total = total + numList[i] average = total/len(numList) return average Hi, I'm really, really new to python, I'm having error on this function and I can't solve it yet, so can someone help? Thank-you :)

Member Avatar for Asset
0
687
Member Avatar for Teiji

Hi, I was checking out the unittest module and try out the sample code. I save the code below in a file call "testrandom.py" and run it using IDLE (Python's default IDE), but I get the following in red. Obviously, the tests run fine as indicated by OK, but why …

Member Avatar for TrustyTony
0
362
Member Avatar for Nassarofficial

The first one is: A program that searches within a file and by user input for a word, and counts how many of this word in the file, and if its in the file or not. Thats what i reached so far: sword, line= 0, 0 filename= raw_input("please input file …

Member Avatar for griswolf
0
93
Member Avatar for Seagull One

I've been working hard all day to get this to work. I'm playing around with the math module in python. I eventually want the following code to help me control the speed of a servo motor. The idea is to get the servo speed to accelerate and then decelerate as …

Member Avatar for woooee
0
189
Member Avatar for TrustyTony

I write usually many versions of the functions, sometimes writing functions from scratch again. Sometimes the parameters change from version to version, sometimes they are refering to library of functions that also has multiple versions. Has somebody advice on how to manage best this kind of situation? Should I define …

0
133
Member Avatar for j855

I have a question. I have a list of numbers like: Bobby 9 9 8 4 8 5 6 7 3 8 6 5 5 7 6 9 6 4 6 4 3 4 7 6 6 I have already written a code to take the numbers in range (1,15) …

Member Avatar for TrustyTony
0
110
Member Avatar for KrazyKitsune

I'm working on a self-project called 'Project Calculus' (Not that you care about the name). It's a huge calculator that works cross-platform and only uses 'already implemented' modules (So no SymPy, no NumPy, no SciPy, et cetera.) in it. I need help (If you even bother to cooperate with a …

Member Avatar for KrazyKitsune
0
123
Member Avatar for masumar

Hi, How do I sum all occurrences of a number in a file? I have a file with a bunch of numbers, each on it's own line: 5 3 11 3 7 3 5 5 11 7 7 ... How do i sum them up so that the output will …

Member Avatar for TrustyTony
0
426
Member Avatar for henryford

Hey guys and gals I am really struggling with this program. I have been working on it for about a week now and every time I think I am getting somewhere it seems like it flops and I get frustrated and start over. I would appreciate it if anyone could …

Member Avatar for griswolf
0
172
Member Avatar for br0wnm4n

def scary(filename): infile = open(filename, 'r') content = infile.read() infile.close() for i in ';",.()[]{}\/0123456789@#!$': content = content.replace(i, ' ') words = content.split() d = {} for word in words: if word in d: continue else: d[words] = words lst = [] for n in d: lst.append(n) lst.sort() outfile = open('dictionary.txt', …

Member Avatar for TrustyTony
0
117
Member Avatar for bambi231991

I need to know if i can take a user inputed string such as [code=python]name = raw_input("Enter Name:")[/code] and take the word inputed and break the string apart by letters for example: If the user enters "joe" i will get "j", "o", "e" is this possible? also i need to …

Member Avatar for TrustyTony
0
121
Member Avatar for sijei

Im a beginner programmer this semester, and python is my first language. I can do the homework but am naturally curious at spiffing up my programs to help me understand how to have many things working at once in a program. I have some ideas but have not been able …

Member Avatar for TrustyTony
0
121
Member Avatar for henryford

I keep getting a error for adding strings and integers together. how can I fix this? It is in the line hours.append(hWork + "\n") [CODE] hours=[] hWork="1" while True: employee=raw_input("\nPlease enter the employees' first and last name. ") hWork=int(raw_input("How many hours did they work this week? ")) if hWork < …

Member Avatar for TrustyTony
0
124
Member Avatar for Chrisfs

Hi, I keep getting the error Traceback (most recent call last): File "<string>", line 11, in <fragment> builtins.TabError: inconsistent use of tabs and spaces in indentation (<wingdb_compile>, line 11) With the lines being [CODE] for line in datafile: pricedata = line.split(",") newdata[pricedata[0]] = pricedata[6][/CODE] I have taken out and put …

Member Avatar for woooee
0
1K
Member Avatar for yeticannotski

Dear All, I am not only new to python, but completely new to programming in general. So please don't laugh (too much) of this certainly dumb question. I was going through the first pages of "A Byte of Python" and decided to change a bit one of the models and …

Member Avatar for yeticannotski
0
82
Member Avatar for akkarin1313

[code]def main(): splash() wordTotal = 0 longestWord = 0 fin = open("constitu.txt") for line in fin: #n = fin.readline() wordLine = line.split() #word = wordLine.split() wordTotal += len(wordLine) #if len(word) >= 15: #longestWord += 1 #print word print "This constitution has ",wordTotal, " words." def splash(): print "This program is …

Member Avatar for woooee
0
2K
Member Avatar for novice20

I have python 2.5.2 on my Debian system n want to upgrade it to python 2.6. Got to know that apt-get install package searches for package in /etc/apt/sources.list I have downloaded python 2.6.2. How to add an entry to the file /etc/apt/sources.list ? :(

Member Avatar for npmaier
0
175
Member Avatar for bpross22

Hi everyone, I am trying to create a list of objects in python. I get the listing of all of the files from the directory that I want. Then I open each file and read it into an appropriate object and append it to the list. For some reason when …

Member Avatar for woooee
0
208
Member Avatar for eldaerys

Howdo you delete a name from the local namespace and occurs as a free variable in a Nest block?

Member Avatar for richieking
0
55
Member Avatar for spacemanspiff92

[CODE]def exportTextList(fileInput, wordList): fileOpen = open(fileInput) for line in fileOpen: line = line.rstrip("\n\r") lineList = line.split() wordList = wordList + lineList return wordList def main(): fileInput = 'PlayerNames.txt' wordList=[] exportTextList(fileInput, wordList) print wordList[/CODE] My code summary: I'm taking a txt file, playernames, and i'm stripping all of the line breaks …

Member Avatar for richieking
0
114
Member Avatar for pacers10

I am having trouble with this problem, I need to enhance the red intensity of each pixel This is what i have [CODE]import cImage def makeRedScale(imageFile): myImageWindow = ImageWin("Image Processing",600,300) oldImage = fileImage(imageFile) oldImage.draw(myImageWindow) width = oldImage.getWidth() height = oldImage.getHeight() newImage = emptyImage (width,height) for row in range(height): for col …

Member Avatar for woooee
0
139
Member Avatar for king_koder

Hi, How do I find the frequency of each item in a list in Python? For example if there are five 'apple', two 'banana', and so on in the list, how do I write a program so that it displays the item as well as the number of times it …

Member Avatar for woooee
0
176
Member Avatar for jackocurly0074

Hi guys, Have been doing some wxPython programming and haven't had any major issues until I wanted to display images! Basically I take readings from an external device (simple input device) and set the image in a panel based on this reading. However it seems that the picture does not …

Member Avatar for cghtkh
0
132
Member Avatar for shashi86

Please someone help to print function has to print numbers like Snack and ladder game when 2 variables rows and columns are passed to a function. ex: fun(4,3) 12 11 10 7 8 9 6 5 4 1 2 3

Member Avatar for TrustyTony
0
187
Member Avatar for python_noobie

Hello: I've been attempting to create a treemap (binary search tree) insertion and display function for a bit and am puzzled by the recursive calls. I've tried quite a few things, but the problem seems to be in my mapInsert function. Here's all the code I've written so far in …

Member Avatar for python_noobie
0
362
Member Avatar for patto78

The following is a recursive function designed to return the factorial of a number. [CODE] def factorial(number, target): if number == 1: return target else: target = target*number factorial((number-1), target) print factorial(7, 1) [/CODE] As you'll see if you run it however it doesn't return my 'target' variable (the factorial …

Member Avatar for patto78
0
187
Member Avatar for knan

I have dictionary with single element lists. [CODE]dictionary={'a':['A'], 'b':['B'], 'c':['C']} [/CODE] How can i change it to [CODE]{'a':'A', 'b':'B','c':'C'}[/CODE]

Member Avatar for TrustyTony
0
147

The End.