Efficient calculation of euclidean distance

I have a MxN array, where M is the number of observations and N is the dimensionality of each vector. From this array of vectors, I need to calculate the mean and minimum euclidean distance between the vectors. In my mind, this requires me to calcu...
more »

2017-03-19 04:03 (0) Answers

find all sublist of list in python

I need to find maximum length of sublist with first element greater than last. if a original list has first element greater than last then i just return the length of list. if not i have to find the sublist of list with maximum length and first elem...
more »

2017-03-18 14:03 (4) Answers

What is the technical term for 'x' in 'for x...'

If I had the code... list = ['Clemont', 'Albert', 'Shiro'] for x in range(len(list)): print(x) ...what would technical term for x be here? I'm assuming it's "iterate object" but maybe that's a misconception; if it's not a misconception, what i...
more »

2017-03-16 22:03 (4) Answers

Make my module a command

I'm pretty sure I read it somewhere but I can't find any doc about it anymore. I did a python (3) module, let say I called it addition. I have my sources, my tests, my setup.py is OK. I can import & use it from anywhere in my system. It's OK. W...
more »

2017-03-16 16:03 (1) Answers

Prime numbers generator explanation?

I was searching for an algorithm to generate prime numbers. I found the following one done by Robert William Hanks. It is very efficient and better than the other algorithms but I can not understand the math behind it. def primes(n): """ Returns...
more »

2017-03-15 14:03 (1) Answers

Saving JSON in Cassandra via Python

I'm trying to save JSON into Cassandra: I have defined my table like: CREATE TABLE IF NOT EXISTS {} ( node_id bigint PRIMARY KEY, tweets list<text> ); I'm using Tweepy to retrieve some tweets via T...
more »

2017-03-12 19:03 (3) Answers

How to Change CharField Choice List Behaviour

As you can see below, I have model with CharField. The user can choose one of the value inside ROLE_CHOICE. Question: How can I make some values unavailable but you can still see them in the selection. Currently, I have tried the following code b...
more »

2017-03-12 05:03 (1) Answers

Alternative Admin in Django

Hello guys I would like to know if there's a way NOT to override Django Admin, but to build your own, with a custom template. I have searched on the internet but there seems to be no answer. I hope there is a person who knows the answer to my questio...
more »

2017-03-11 20:03 (1) Answers

Pattern database and Rubik's Cube

I'm trying to code an algorithm to solve a 2x2 Rubik's Cube optimally (least moves). I chose to implement the IDA* algorithm but i want to code the heuristic function with a pattern database and here comes my question : How go i even index my cubies...
more »

2017-03-11 18:03 (0) Answers

How to avoid typing a long series of variables

New to stackoverflow and fairly new to programming. I have a set of 32 equations in 32 unknowns. I want to solve this equation using np.linalg.solve: for a1 * x + b1 * y = c1 and a2 * x + b2 * y = C2 (x and y are unknowns; a, b and c are variables...
more »

2017-03-09 18:03 (2) Answers

How to convert json to object?

I need to convert a json-string to python object. By object I mean "new" python3 object like: class MyClass(object): I found several help for example on jsonpickle documentation. But all I found are tutorials which convert object to json first and...
more »

2017-03-08 13:03 (2) Answers

Formatting the print of a path in 2d grid

I have a 2d grid and a path through the grid like so: grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] path = [(0, 0), (1, 0), (2, 0), (2, 1), (2, 2)] My desired result is a nicely formatted output depicting the grid with the path shown: *1 2 3 *...
more »

2017-03-05 20:03 (3) Answers

how to update a text in a file line by line

I have a text file foo.txt that looks like: first 01 start some thing 01 and more 101 i dont care end i dont care final 01 I want to replace all 01 with 10 between the lines start and end in the same foo.txt like so: first 01 star...
more »

2017-03-03 19:03 (1) Answers

pandas groupby with count, sum and avg

I have a following DF in pandas: +---------+--------+--------------------+ | keyword | weight | other keywords | +---------+--------+--------------------+ | dog | 0.12 | [cat, horse, pig] | | cat | 0.5 | [dog, pig, camel] | | hors...
more »

2017-03-03 10:03 (1) Answers

Type hinting generator in python 3.6

According to PEP-484, we should be able to type hinting a generator function as follows: from typing import Generator def generate() -> Generator[int, None, None]: for i in range(10): yield i for i in generate(): print(i) Howe...
more »

2017-03-01 12:03 (2) Answers

Can I postpone the evaluation of f-strings?

I am using template strings to generate some files and I love conciseness of the new f-strings for this purpose. Previously I would do something like this: template_a = "The current name is {name}" names = ["foo", "bar"] for name in names: pri...
more »

2017-02-28 00:02 (4) Answers