Use numpy to generate all possible combinations in a range using numpy in python
Is there a faster way to generate possible combinations without repetitions in numpy? For example, if I needed all 3 number combinations in range(1,5) I will get (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4).I'm using the following code which works but is quite slow for me and am wondering if there's a faster method:
from itertools import *
result=[]
for c in combinations(range(1,48), 6):
result.append(c)
See also questions close to this topic

read and split information from text file python
I'm stuck on a problem:
I have a text file called id_numbers.txt that contains this information:
325255, Jan Jansen
334343, Erik Materus
235434, Ali Ahson
645345, Eva Versteeg
534545, Jan de Wilde
345355, Henk de Vries
I need python to split the information at the comma and write a program that will the display the information as follows:
Jan Jansen has cardnumber: 325255
Erik Materus has cardnumber: 334343
Ali Ahson has cardnumber: 235434
Eva Versteeg has cardnumber: 645345
I've tried to convert to list and split(",") but that ends up adding the next number like this:
['325255', ' Jan Jansen\n334343', ' Erik Materus\n235434', ' Ali Ahson\n645345', ' Eva Versteeg\n534545', ' Jan de Wilde\n345355', ' Henk de Vries']
Help would be appreciated!

Excel library to use
I'm quite new to programming, I've just started an internship as a programmer and have been learning since then. My team uses PHPExcel library and they are thinking about swaping to another one, in python, so probably openpyxl.
I have been doing some research but could not find any information about which one has a better potential, only that the python one was developed based on PHPExcel, can anyone share information on this?
I know this might not be the right place to ask but I could not find anywhere else.

python break not working(nested for loop)
I don't know why is the break statement still continue to execute the outer for loop
x=0 password="" password=input("enter your password") crack="" c=0 for a in range(9,127): print("length",a) for a1 in range(9,127): for a2 in range(9,127): for a2 in range(9,127): if password==crack: print("password",crack) crack=chr(a)+chr(a1)+chr(a2) print("password",crack)

Not enough values to unpack python and opencv
I'm new to python and opencv. I tried this motion detection code and it worked fine.
import numpy as np import cv2 from os import walk import os sdThresh = 10 font = cv2.FONT_HERSHEY_SIMPLEX def distMap(frame1, frame2): """outputs pythagorean distance between two frames""" frame1_32 = np.float32(frame1) frame2_32 = np.float32(frame2) diff32 = frame1_32  frame2_32 norm32 = np.sqrt(diff32[:,:,0]**2 + diff32[:,:,1]**2 + diff32[:,:,2]**2)/np.sqrt(255**2 + 255**2 + 255**2) dist = np.uint8(norm32*255) return dist cv2.namedWindow('frame') cv2.namedWindow('dist') #capture video stream from camera source. 0 refers to first camera, 1 referes to 2nd and so on. loc = os.path.abspath('') cap = cv2.VideoCapture(loc+'/inputs/video.avi') _, frame1 = cap.read() _, frame2 = cap.read() while(True): _, frame3 = cap.read() rows, cols, _ = np.shape(frame3) cv2.imshow('dist', frame3) dist = distMap(frame1, frame2) frame1 = frame2 frame2 = frame3 # apply Gaussian smoothing mod = cv2.GaussianBlur(dist, (15,15), 0) # apply thresholding _, thresh = cv2.threshold(mod, 100, 200, 0) # calculate st dev test _, stDev = cv2.meanStdDev(mod) cv2.imshow('dist', mod) cv2.putText(frame2, "Standard Deviation  {}".format(round(stDev[0][0],0)), (70, 70), font, 1, (255, 0, 255), 1, cv2.LINE_AA) if stDev > sdThresh: print("Motion detected.."); else: print("No motion Detected"); cv2.imshow('frame', frame2) if cv2.waitKey(1) & 0xFF == 27: break cap.release() cv2.destroyAllWindows()
But when i tried to modify it by putting it inside of a function it is giving me an error saying not enough values to unpack and in my editor variables cols, rows and thresh are indicated as unused. I cannot figure out what exactly is wrong with it. A help will be kindly appreciated
import numpy as np import cv2 from os import walk import os sdThresh = 10 font = cv2.FONT_HERSHEY_SIMPLEX def distMap(frame1, frame2): """outputs pythagorean distance between two frames""" frame1_32 = np.float32(frame1) frame2_32 = np.float32(frame2) diff32 = frame1_32  frame2_32 norm32 = np.sqrt(diff32[:,:,0]**2 + diff32[:,:,1]**2 + diff32[:,:,2]**2)/np.sqrt(255**2 + 255**2 + 255**2) dist = np.uint8(norm32*255) return dist def MotionDetect(): cv2.namedWindow('frame') cv2.namedWindow('dist') loc = os.path.abspath('') cap = cv2.VideoCapture(loc+'/inputs/video.avi') _, frame1 = cap.read() _, frame2 = cap.read() while(True): _, frame3 = cap.read() rows, cols, _ = np.shape(frame3) cv2.imshow('dist', frame3) dist = distMap(frame1, frame2) frame1 = frame2 frame2 = frame3 # apply Gaussian smoothing mod = cv2.GaussianBlur(dist, (15,15), 0) # apply thresholding _, thresh = cv2.threshold(mod, 100, 200, 0) # calculate st dev test _, stDev = cv2.meanStdDev(mod) cv2.imshow('dist', mod) cv2.putText(frame2, "Standard Deviation  {}".format(round(stDev[0][0],0)), (70, 70), font, 1, (255, 0, 255), 1, cv2.LINE_AA) if stDev > sdThresh: print("Motion detected..") else: print("No motion Detected") cv2.imshow('frame', frame2) if cv2.waitKey(1) & 0xFF == 27: break cap.release() cv2.destroyAllWindows() return MotionDetect()

numpy.minimum for complex numbers
numpy.minimum does not seem to work for complex numbers:
np.minimum(5+3*1j,4+30*1j) (4+30j)
I want to keep the value with the maximum magnitude. It only compares the real part. Any other function for elementwise minimum comparison? MATLAB min does work with complex numbers. Thanks

Map python nested list into multiple sublists
I have a python list
[['a'],['b','c'],['c','d']]
.How can I map this array into multiple arrays ?
['a', 'b', 'c'] ['a', 'c', 'c'] ['a', 'b', 'd'] ['a', 'c', 'd']
I tried to do it as matrix multiplication, but I cannot do multiple in numpy for string type.

Combinations are not calculated correctly
I found on Wikipedia that C(n,k) = (nk+1)/k * C(n, k1). I did the evidence myself and got that it was correct. Then I implemented it in my function, which is suppose to calculate combinations using recursion without hitting the builtin limit in python. This worked great.. until I put in to great numbers. This is my function:
def choose(n, k): if not k: return 1 elif n < k: return 0 else: return int((((n  k + 1) / k)) * choose(n, (k  1)))
It worked if you would use lower numbers such as choose(1000, 4), but if you try numbers such as choose(1000,800) it will return the first 13 number right, but then get everything wrong. How come this occurs and even more important, how do you solve it?

Using expand.grid function with n elements
I need to generate all the combinations of
1:n
repeatedn
times. Example withn = 4
:expand.grid(1:4, 1:4, 1:4, 1:4)
This method, however, will require a lot of typing when
n
is a larger number. Is there an efficient way to do this? I Triedpaste
and couldn't make it work. 
Recursive function for finding combinations without hitting the builtin limit in python
I have put together a function for finding combinations using recursion without hitting the built in limit in python. For example you could calculate: choose(1000, 500). This is how it looks right now:
def choose(n, k): if not k: return 1 . elif n < k: return 0 else: return ((n + 1  k) / k) * choose(n, k  1)
It works exactly how I want it to work. If k is 0 then return 1 and if n is less then k then return 0 (this is according to the mathematical definitions I found on wikipedia). However, the problem is that I don't quite understand the last row (found it when I was browsing the web). Before the last row I'm using at the moment, this was the last row I had in the function:
return choose(n1,k1) + choose(n1, k)
Which I also found on wikipedia (though I don't think I understand this one a 100% as well). But it would always result in an error because of the built in limitation in python, whereas the new line I'm using does not result in such an error. I understand that the new line works much more efficient with the program, because we for example don't split it up to two subproblems.
So again.. what I'm asking is if there are any kind souls out there that could explain (in an understandable manner) how this line of code works in the function:
return ((n + 1  k) / k) * choose(n, k  1)