qid int64 46k 74.7M | question stringlengths 54 37.8k | date stringlengths 10 10 | metadata listlengths 3 3 | response_j stringlengths 17 26k | response_k stringlengths 26 26k |
|---|---|---|---|---|---|
52,425,065 | How can I use Python 3.7 in my command line?
My Python interpreter is active on Python 3.7 and my python.pythonPath is `/usr/local/bin/python3`, though my Python version in my command line is 2.7. I've already installed Python 3.7 on my mac.
```
lorenzs-mbp:Python lorenzkort$ python --version
Python 2.7.13
``` | 2018/09/20 | [
"https://Stackoverflow.com/questions/52425065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7866979/"
] | If you open tab "Terminal" in your VSCode then your default python is called (in your case python2).
If you want to use python3.7 try to use following command:
```
python3 --version
```
Or just type the full path to the python folder:
```
/usr/local/bin/python3 yourscript.py
```
In case you want to change defaul... | You should use `python3` instead of `python` for running any commands you want to run then it will use the python3 version interpreter.
Also if you are using `pip` then use `pip3`.
Hope this helps. |
52,425,065 | How can I use Python 3.7 in my command line?
My Python interpreter is active on Python 3.7 and my python.pythonPath is `/usr/local/bin/python3`, though my Python version in my command line is 2.7. I've already installed Python 3.7 on my mac.
```
lorenzs-mbp:Python lorenzkort$ python --version
Python 2.7.13
``` | 2018/09/20 | [
"https://Stackoverflow.com/questions/52425065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7866979/"
] | If you open tab "Terminal" in your VSCode then your default python is called (in your case python2).
If you want to use python3.7 try to use following command:
```
python3 --version
```
Or just type the full path to the python folder:
```
/usr/local/bin/python3 yourscript.py
```
In case you want to change defaul... | This gives you a complete guide in setting up Visual Studio code for python
[Getting Started with Python in VS Code](https://code.visualstudio.com/docs/python/python-tutorial) |
44,628,186 | I encounter many tasks in which I need to filter python (2.7) list to keep only ordered unique values. My usual approach is by using `odereddict` from collections:
```
from collections import OrderedDict
ls = [1,2,3,4,1,23,4,12,3,41]
ls = OrderedDict(zip(ls,['']*len(ls))).keys()
print ls
```
the output is:
>
> ... | 2017/06/19 | [
"https://Stackoverflow.com/questions/44628186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3861108/"
] | If you need to preserve the order **and** get rid of the duplicates, you can do it like:
```
ls = [1, 2, 3, 4, 1, 23, 4, 12, 3, 41]
lookup = set() # a temporary lookup set
ls = [x for x in ls if x not in lookup and lookup.add(x) is None]
# [1, 2, 3, 4, 23, 12, 41]
```
This should be **considerably** faster than yo... | You could use a [set](https://docs.python.org/2/library/stdtypes.html#set) like this:
```
newls = []
seen = set()
for elem in ls:
if not elem in seen:
newls.append(elem)
seen.add(elem)
``` |
44,628,186 | I encounter many tasks in which I need to filter python (2.7) list to keep only ordered unique values. My usual approach is by using `odereddict` from collections:
```
from collections import OrderedDict
ls = [1,2,3,4,1,23,4,12,3,41]
ls = OrderedDict(zip(ls,['']*len(ls))).keys()
print ls
```
the output is:
>
> ... | 2017/06/19 | [
"https://Stackoverflow.com/questions/44628186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3861108/"
] | If you need to preserve the order **and** get rid of the duplicates, you can do it like:
```
ls = [1, 2, 3, 4, 1, 23, 4, 12, 3, 41]
lookup = set() # a temporary lookup set
ls = [x for x in ls if x not in lookup and lookup.add(x) is None]
# [1, 2, 3, 4, 23, 12, 41]
```
This should be **considerably** faster than yo... | Define a function to do so:
```
def uniques(l):
retl = []
for x in l:
if x not in retl:
retl.append(x)
return retl
ls = [1,2,3,4,1,23,4,12,3,41]
uniques(ls)
[1, 2, 3, 4, 23, 12, 41]
``` |
44,628,186 | I encounter many tasks in which I need to filter python (2.7) list to keep only ordered unique values. My usual approach is by using `odereddict` from collections:
```
from collections import OrderedDict
ls = [1,2,3,4,1,23,4,12,3,41]
ls = OrderedDict(zip(ls,['']*len(ls))).keys()
print ls
```
the output is:
>
> ... | 2017/06/19 | [
"https://Stackoverflow.com/questions/44628186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3861108/"
] | If you need to preserve the order **and** get rid of the duplicates, you can do it like:
```
ls = [1, 2, 3, 4, 1, 23, 4, 12, 3, 41]
lookup = set() # a temporary lookup set
ls = [x for x in ls if x not in lookup and lookup.add(x) is None]
# [1, 2, 3, 4, 23, 12, 41]
```
This should be **considerably** faster than yo... | Another solution would be using list comprehension like this:
```
[x for i, x in enumerate(ls) if x not in ls[:i]]
```
Output:
```
[1, 2, 3, 4, 23, 12, 41]
``` |
44,628,186 | I encounter many tasks in which I need to filter python (2.7) list to keep only ordered unique values. My usual approach is by using `odereddict` from collections:
```
from collections import OrderedDict
ls = [1,2,3,4,1,23,4,12,3,41]
ls = OrderedDict(zip(ls,['']*len(ls))).keys()
print ls
```
the output is:
>
> ... | 2017/06/19 | [
"https://Stackoverflow.com/questions/44628186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3861108/"
] | You could use a [set](https://docs.python.org/2/library/stdtypes.html#set) like this:
```
newls = []
seen = set()
for elem in ls:
if not elem in seen:
newls.append(elem)
seen.add(elem)
``` | Define a function to do so:
```
def uniques(l):
retl = []
for x in l:
if x not in retl:
retl.append(x)
return retl
ls = [1,2,3,4,1,23,4,12,3,41]
uniques(ls)
[1, 2, 3, 4, 23, 12, 41]
``` |
44,628,186 | I encounter many tasks in which I need to filter python (2.7) list to keep only ordered unique values. My usual approach is by using `odereddict` from collections:
```
from collections import OrderedDict
ls = [1,2,3,4,1,23,4,12,3,41]
ls = OrderedDict(zip(ls,['']*len(ls))).keys()
print ls
```
the output is:
>
> ... | 2017/06/19 | [
"https://Stackoverflow.com/questions/44628186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3861108/"
] | You could use a [set](https://docs.python.org/2/library/stdtypes.html#set) like this:
```
newls = []
seen = set()
for elem in ls:
if not elem in seen:
newls.append(elem)
seen.add(elem)
``` | Another solution would be using list comprehension like this:
```
[x for i, x in enumerate(ls) if x not in ls[:i]]
```
Output:
```
[1, 2, 3, 4, 23, 12, 41]
``` |
38,521,553 | I have two files representing records with intervals.
file1.txt
```none
a 5 10
a 13 19
a 27 39
b 4 9
b 15 19
c 20 33
c 39 45
```
and
file2.txt
```none
something id1 a 4 9 commentx
something id2 a 14 18 commenty
something id3 a 1 4 commentz
something id5 b 3 9 commentbla
something id6 b 16 18 commentbla
something ... | 2016/07/22 | [
"https://Stackoverflow.com/questions/38521553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613786/"
] | Do looping in a loop is not a good way. Try to avoid to do such things.
I think you could cache the content of file1 first use a dict object. Then, when looping file2 you can use the dict object to find your need things.So, i will code like bellow:
```
with open("file1.csv", "r") as protein, open("file2.csv", "r") as ... | For your code to work, you will have to change three things:
1. Your loop over the position reader is only run once, because the reader runs through the file, the first time the loop is run. Afterwards, he searches for the next item at the end of the file. You'll have to rewind the file each time, before the loop is r... |
38,521,553 | I have two files representing records with intervals.
file1.txt
```none
a 5 10
a 13 19
a 27 39
b 4 9
b 15 19
c 20 33
c 39 45
```
and
file2.txt
```none
something id1 a 4 9 commentx
something id2 a 14 18 commenty
something id3 a 1 4 commentz
something id5 b 3 9 commentbla
something id6 b 16 18 commentbla
something ... | 2016/07/22 | [
"https://Stackoverflow.com/questions/38521553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613786/"
] | It might be overkill, but you could create a class to represent intervals and use it to make fairly readable code:
```
import csv
class Interval(object):
""" Representation of a closed interval.
a & b can be numeric, a datetime.date, or any other comparable type.
"""
def __init__(self, a, b):
... | For your code to work, you will have to change three things:
1. Your loop over the position reader is only run once, because the reader runs through the file, the first time the loop is run. Afterwards, he searches for the next item at the end of the file. You'll have to rewind the file each time, before the loop is r... |
38,521,553 | I have two files representing records with intervals.
file1.txt
```none
a 5 10
a 13 19
a 27 39
b 4 9
b 15 19
c 20 33
c 39 45
```
and
file2.txt
```none
something id1 a 4 9 commentx
something id2 a 14 18 commenty
something id3 a 1 4 commentz
something id5 b 3 9 commentbla
something id6 b 16 18 commentbla
something ... | 2016/07/22 | [
"https://Stackoverflow.com/questions/38521553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613786/"
] | Do looping in a loop is not a good way. Try to avoid to do such things.
I think you could cache the content of file1 first use a dict object. Then, when looping file2 you can use the dict object to find your need things.So, i will code like bellow:
```
with open("file1.csv", "r") as protein, open("file2.csv", "r") as ... | Here is an algorithm working for you:
```
def is_overlapping(x, y):
return len(range(max(x[0], y[0]), min(x[-1], y[-1])+1)) > 0
position_file = r"file1.txt"
positions = [line.strip().split() for line in open(position_file).read().split('\n')]
protein_file = r"file2.txt"
proteins = [(line.strip().split()[2:5], li... |
38,521,553 | I have two files representing records with intervals.
file1.txt
```none
a 5 10
a 13 19
a 27 39
b 4 9
b 15 19
c 20 33
c 39 45
```
and
file2.txt
```none
something id1 a 4 9 commentx
something id2 a 14 18 commenty
something id3 a 1 4 commentz
something id5 b 3 9 commentbla
something id6 b 16 18 commentbla
something ... | 2016/07/22 | [
"https://Stackoverflow.com/questions/38521553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613786/"
] | It might be overkill, but you could create a class to represent intervals and use it to make fairly readable code:
```
import csv
class Interval(object):
""" Representation of a closed interval.
a & b can be numeric, a datetime.date, or any other comparable type.
"""
def __init__(self, a, b):
... | Here is an algorithm working for you:
```
def is_overlapping(x, y):
return len(range(max(x[0], y[0]), min(x[-1], y[-1])+1)) > 0
position_file = r"file1.txt"
positions = [line.strip().split() for line in open(position_file).read().split('\n')]
protein_file = r"file2.txt"
proteins = [(line.strip().split()[2:5], li... |
38,521,553 | I have two files representing records with intervals.
file1.txt
```none
a 5 10
a 13 19
a 27 39
b 4 9
b 15 19
c 20 33
c 39 45
```
and
file2.txt
```none
something id1 a 4 9 commentx
something id2 a 14 18 commenty
something id3 a 1 4 commentz
something id5 b 3 9 commentbla
something id6 b 16 18 commentbla
something ... | 2016/07/22 | [
"https://Stackoverflow.com/questions/38521553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613786/"
] | Do looping in a loop is not a good way. Try to avoid to do such things.
I think you could cache the content of file1 first use a dict object. Then, when looping file2 you can use the dict object to find your need things.So, i will code like bellow:
```
with open("file1.csv", "r") as protein, open("file2.csv", "r") as ... | It might be overkill, but you could create a class to represent intervals and use it to make fairly readable code:
```
import csv
class Interval(object):
""" Representation of a closed interval.
a & b can be numeric, a datetime.date, or any other comparable type.
"""
def __init__(self, a, b):
... |
65,891,227 | this is probably a pretty dumb question..
I was fooling around some in python and decided to make two version of prime number apps, one that just indefinately counts up all prime-numbers from start until you fry ur pc and one that lets the user input a number and then checks if the number is a prime number or not.
So ... | 2021/01/25 | [
"https://Stackoverflow.com/questions/65891227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15040876/"
] | You need to fix `scripts/start.js` file.
There is a line in this file:
```
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
```
You need to change it to
```
const compiler = createCompiler({ webpack, config, appName, urls, useYarn });
```
This change will fix your current error but proba... | Try updating your `node` part for webpack 5 as well. What was
```
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
}
```
has to be under `resolve.fallback`.
Source: <https://webpack.js.org/migrate/5/#clean-up-configuration> |
65,891,227 | this is probably a pretty dumb question..
I was fooling around some in python and decided to make two version of prime number apps, one that just indefinately counts up all prime-numbers from start until you fry ur pc and one that lets the user input a number and then checks if the number is a prime number or not.
So ... | 2021/01/25 | [
"https://Stackoverflow.com/questions/65891227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15040876/"
] | You need to fix `scripts/start.js` file.
There is a line in this file:
```
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
```
You need to change it to
```
const compiler = createCompiler({ webpack, config, appName, urls, useYarn });
```
This change will fix your current error but proba... | ```
new webpack.LoaderOptionsPlugin({
options: {
applyWebpackOptionsDefaults: {},
```
From your code... |
12,243,891 | How do i achieve line 9 and 10 i.e the two `for` loops in python
```
matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
newMatrix = []
for (i=0; i < len(matrix); i++):
for (j=0; j < len(matrix[i]); j++):
newMatrix[j][i] = matrix[i][j]
print newMatrix
```
PS: i know i can do `[[row[i]... | 2012/09/03 | [
"https://Stackoverflow.com/questions/12243891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/406659/"
] | Use `range` (or `xrange`).
```
for i in range(len(matrix)):
for j in range(len(matrix[i])):
```
FYI, assigning to `newMatrix[i][j]` will fail, because `newMatrix` is an empty `list`. You need to add a new empty `list` to `newMatrix` for every row and then append the new value to that list in every iteration. | You can use the [`enumerate()` function](http://docs.python.org/library/functions.html#enumerate) to loop over both the matrix values and give you indices:
```
newMatrix = [[0] * len(matrix) for _ in xrange(len(matrix[0]))]
for i, row in enumerate(matrix):
for j, value in enumerate(row):
newMatrix[j][i] = ... |
12,243,891 | How do i achieve line 9 and 10 i.e the two `for` loops in python
```
matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
newMatrix = []
for (i=0; i < len(matrix); i++):
for (j=0; j < len(matrix[i]); j++):
newMatrix[j][i] = matrix[i][j]
print newMatrix
```
PS: i know i can do `[[row[i]... | 2012/09/03 | [
"https://Stackoverflow.com/questions/12243891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/406659/"
] | Use `range` (or `xrange`).
```
for i in range(len(matrix)):
for j in range(len(matrix[i])):
```
FYI, assigning to `newMatrix[i][j]` will fail, because `newMatrix` is an empty `list`. You need to add a new empty `list` to `newMatrix` for every row and then append the new value to that list in every iteration. | Just to throw something else into the mix of answers, if you are doing *any* kind of matrix operations with Python, consider using [`numpy`](http://numpy.scipy.org/):
```
>>> import numpy
>>> matrix = numpy.matrix([
... [1, 2, 3, 4],
... [5, 6, 7, 8],
... [9, 10, 11, 12]
... ])
```
The transpose is prett... |
12,243,891 | How do i achieve line 9 and 10 i.e the two `for` loops in python
```
matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
newMatrix = []
for (i=0; i < len(matrix); i++):
for (j=0; j < len(matrix[i]); j++):
newMatrix[j][i] = matrix[i][j]
print newMatrix
```
PS: i know i can do `[[row[i]... | 2012/09/03 | [
"https://Stackoverflow.com/questions/12243891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/406659/"
] | Use `range` (or `xrange`).
```
for i in range(len(matrix)):
for j in range(len(matrix[i])):
```
FYI, assigning to `newMatrix[i][j]` will fail, because `newMatrix` is an empty `list`. You need to add a new empty `list` to `newMatrix` for every row and then append the new value to that list in every iteration. | If I understand you correctly, what you want to do is a [matrix transposition](http://en.wikipedia.org/wiki/Transpose), which can be done this way:
```
zip(*matrix)
``` |
1,478,178 | Usually, the best practice in python, when using international languages, is to use unicode and to convert early any input to unicode and to convert late to a string encoding (UTF-8 most of the times).
But when I need to do RegEx on unicode I don't find the process really friendly. For example, if I need to find the '... | 2009/09/25 | [
"https://Stackoverflow.com/questions/1478178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | I haven't used a JDBC-ODBC bridge in quite a few years, but I would expect that the ODBC driver's fetch size would be controlling. What ODBC driver are you using and what version of the ODBC driver are you using? What is the fetch size specified in the DSN?
As a separate issue, I would seriously question your decision... | Use JDBC. There is no advantage in using ODBC bridge. In PreparedStatement or CallableStatement you can call setFetchSize() to restrict the rowset size. |
1,478,178 | Usually, the best practice in python, when using international languages, is to use unicode and to convert early any input to unicode and to convert late to a string encoding (UTF-8 most of the times).
But when I need to do RegEx on unicode I don't find the process really friendly. For example, if I need to find the '... | 2009/09/25 | [
"https://Stackoverflow.com/questions/1478178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | I haven't used a JDBC-ODBC bridge in quite a few years, but I would expect that the ODBC driver's fetch size would be controlling. What ODBC driver are you using and what version of the ODBC driver are you using? What is the fetch size specified in the DSN?
As a separate issue, I would seriously question your decision... | Are you sure the fetch size makes any difference in Sun's ODBC-JDBC driver? We tried it a few years ago with Java 5. The value is set, even validated but never used. I suspect it's still the case. |
59,357,940 | The below piece of code uses openCV module to identify lanes on road. I use the python 3.6 for coding (I use atom IDE for development. This info is being provided because stackoverflow isn't letting me post the info without unnecessary lines of info. so please ignore the comments in bracket)
The code runs fine with a g... | 2019/12/16 | [
"https://Stackoverflow.com/questions/59357940",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12181181/"
] | In some of the frames all the slope are > 0 hence left\_fit list is empty. Because of that you are getting error when you are calculating left\_fit average. One of the way to solve this problem to use left\_fit average from previous frame. I have solved it using the same approach. Please see the code below and let me k... | `HoughLinesP` returns a list and that can be an empty list and not necessarily `None`
So the lines in the function `average_slope_intercept`
```
if lines is None:
return None
```
is not much of use.
You need to check `len(lines) == 0` |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | With `zip()` and `itertools.izip_longest()` you can do that like:
### Code:
```
import itertools as it
in_data = list('ABCDEFGHIJKLMNOPQ')
out_data = {k: list(v) if v else [] for k, v in
it.izip_longest(in_data, zip(in_data[1::2], in_data[2::2]))}
import json
print(json.dumps(out_data, indent=2))
```
... | You can use `itertools`:
```
from itertools import chain, repeat
data = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q']
lists = [[first, second] for first, second in zip(data[1::2], data[2::2])]
result = {char: list(value) for char, value in zip(data, chain(lists, repeat([])))}
... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | With `zip()` and `itertools.izip_longest()` you can do that like:
### Code:
```
import itertools as it
in_data = list('ABCDEFGHIJKLMNOPQ')
out_data = {k: list(v) if v else [] for k, v in
it.izip_longest(in_data, zip(in_data[1::2], in_data[2::2]))}
import json
print(json.dumps(out_data, indent=2))
```
... | you can create tree topology dict by index relation:
```
def generateTree(arr):
tree = {}
for i, v in enumerate(arr):
tree[v] = []
if i * 2 + 1 < len(arr):
tree[v].append(arr[i * 2 + 1])
if i * 2 + 2 < len(arr):
tree[v].append(arr[i * 2 + 2])
return tree
```... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | With `zip()` and `itertools.izip_longest()` you can do that like:
### Code:
```
import itertools as it
in_data = list('ABCDEFGHIJKLMNOPQ')
out_data = {k: list(v) if v else [] for k, v in
it.izip_longest(in_data, zip(in_data[1::2], in_data[2::2]))}
import json
print(json.dumps(out_data, indent=2))
```
... | try this:
```
LL = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
dd = {}
for i,e in enumerate(LL):
LLL = []
if ((i+1) + len(dd) < len(LL)): LLL = [LL[((i+1) + len(dd))], LL[((i+1) + len(dd))+1]]
dd[e] = LLL
print dd
{'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F', 'G'],
'D': [... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | Here's an old-fashion method that's pretty optimized that uses the array indexing method as described in the following tutorial: <https://www.geeksforgeeks.org/construct-complete-binary-tree-given-array/>
The first line fills out the non-leaves with the values of children. The second line fills the leaves to be empty ... | You can use `itertools`:
```
from itertools import chain, repeat
data = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q']
lists = [[first, second] for first, second in zip(data[1::2], data[2::2])]
result = {char: list(value) for char, value in zip(data, chain(lists, repeat([])))}
... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | ```
alphabet=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
d={} # empty dictionary
counter=2
for i in range(0,len(alphabet)):
if i==0: # at letter 'A' only
lst=[alphabet[i+1],alphabet[i+2]] # lst that will be used as value of key in dictionary
elif i<(len(alphabet)-1)/2: # at l... | You can use `itertools`:
```
from itertools import chain, repeat
data = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q']
lists = [[first, second] for first, second in zip(data[1::2], data[2::2])]
result = {char: list(value) for char, value in zip(data, chain(lists, repeat([])))}
... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | Here's an old-fashion method that's pretty optimized that uses the array indexing method as described in the following tutorial: <https://www.geeksforgeeks.org/construct-complete-binary-tree-given-array/>
The first line fills out the non-leaves with the values of children. The second line fills the leaves to be empty ... | you can create tree topology dict by index relation:
```
def generateTree(arr):
tree = {}
for i, v in enumerate(arr):
tree[v] = []
if i * 2 + 1 < len(arr):
tree[v].append(arr[i * 2 + 1])
if i * 2 + 2 < len(arr):
tree[v].append(arr[i * 2 + 2])
return tree
```... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | ```
alphabet=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
d={} # empty dictionary
counter=2
for i in range(0,len(alphabet)):
if i==0: # at letter 'A' only
lst=[alphabet[i+1],alphabet[i+2]] # lst that will be used as value of key in dictionary
elif i<(len(alphabet)-1)/2: # at l... | you can create tree topology dict by index relation:
```
def generateTree(arr):
tree = {}
for i, v in enumerate(arr):
tree[v] = []
if i * 2 + 1 < len(arr):
tree[v].append(arr[i * 2 + 1])
if i * 2 + 2 < len(arr):
tree[v].append(arr[i * 2 + 2])
return tree
```... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | Here's an old-fashion method that's pretty optimized that uses the array indexing method as described in the following tutorial: <https://www.geeksforgeeks.org/construct-complete-binary-tree-given-array/>
The first line fills out the non-leaves with the values of children. The second line fills the leaves to be empty ... | try this:
```
LL = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
dd = {}
for i,e in enumerate(LL):
LLL = []
if ((i+1) + len(dd) < len(LL)): LLL = [LL[((i+1) + len(dd))], LL[((i+1) + len(dd))+1]]
dd[e] = LLL
print dd
{'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F', 'G'],
'D': [... |
55,554,816 | In python2.7, I have one list
```
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
```
and I need to transform into a dict like
```
{
'A':['B','C'],
'B':['D','E'],
'C':['F','G'],
'D':['H','I'],
'E':['J','K'],
'F':['L','M'],
'G':['N','O'],
'H':['P','Q'],
'I':[],
'J':[],
'K':[],
'L':[],
'M':[],
... | 2019/04/07 | [
"https://Stackoverflow.com/questions/55554816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11322996/"
] | ```
alphabet=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
d={} # empty dictionary
counter=2
for i in range(0,len(alphabet)):
if i==0: # at letter 'A' only
lst=[alphabet[i+1],alphabet[i+2]] # lst that will be used as value of key in dictionary
elif i<(len(alphabet)-1)/2: # at l... | try this:
```
LL = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
dd = {}
for i,e in enumerate(LL):
LLL = []
if ((i+1) + len(dd) < len(LL)): LLL = [LL[((i+1) + len(dd))], LL[((i+1) + len(dd))+1]]
dd[e] = LLL
print dd
{'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F', 'G'],
'D': [... |
51,961,416 | i am trying to copy line from text file in zip folder by matching partial string,
zip folders are in a shared folder
is there a way to copy strings from text files and send it to one output text file.
how to do it using python..
is it possible with zip\_archive?
i tried using this, with no luck.
```
zf = zipfile.ZipF... | 2018/08/22 | [
"https://Stackoverflow.com/questions/51961416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10258075/"
] | Unlike *@strava* answer, you don't actually have to extract... `zipfile` gives you excellent [API](https://docs.python.org/3/library/zipfile.html) for manipulating files. Here is a simple example of reading each file inside a simple zip (I zipped only one `.txt` file):
```
import zipfile
zip_path = r'C:\Users\avi_na\D... | You could try extracting them first, and then treating them as normal csv files
```
zf = zipfile.ZipFile( path to zip )
zf.extract('first.csv', path to save directory )
file = open('path\first.csv')
``` |
51,961,416 | i am trying to copy line from text file in zip folder by matching partial string,
zip folders are in a shared folder
is there a way to copy strings from text files and send it to one output text file.
how to do it using python..
is it possible with zip\_archive?
i tried using this, with no luck.
```
zf = zipfile.ZipF... | 2018/08/22 | [
"https://Stackoverflow.com/questions/51961416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10258075/"
] | Unlike *@strava* answer, you don't actually have to extract... `zipfile` gives you excellent [API](https://docs.python.org/3/library/zipfile.html) for manipulating files. Here is a simple example of reading each file inside a simple zip (I zipped only one `.txt` file):
```
import zipfile
zip_path = r'C:\Users\avi_na\D... | Here it is a script that does what *I suppose* you need — please note that we DO NOT need `pandas` if we want to simply match a string against a line's content, it'd be different if you want to match on a specific field, a numerical value etc — hence I am not using `pandas`...
```
$ cat zip.py
from sys import argv
fro... |
69,979,362 | I have a csv that I need to convert to XML using Python. I'm a novice python dev.
Example CSV data:
```
Amount,Code
CODE50,1246
CODE50,6290
CODE25,1077
CODE25,9790
CODE100,5319
CODE100,4988
```
Necessary output XML
```
<coupon-codes coupon-id="CODE50">
<code>1246</code>
<code>1246</code>
<coupon-codes/>
<c... | 2021/11/15 | [
"https://Stackoverflow.com/questions/69979362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9803155/"
] | Here how you do it:
```
Expanded(
child: CustomPaint(
painter: MyCustomPainter(),
size: Size.infinite,
),
),
``` | You can get height and width of the screen by using MediaQuery and use them
```
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
return CustomPaint(
size: Size(width,height),
painter: Sky(),
child: const Center(
child: Text(
... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | python is slower then perl. It may be faster to develop but it doesnt execute faster here is one benchmark <http://xodian.net/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html> -edit- a terrible benchmark but it is at least a real benchmark with numbers and not some guess. To bad theres... | I'm not up-to-date on everything with Python, but my first idea about this benchmark was the difference between Perl and Python numbers. In Perl, we have numbers. They aren't objects, and their precision is limited to the sizes imposed by the architecture. In Python, we have objects with arbitrary precision. For small ... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | The nit-picking answer is that you should compare it to idiomatic Python:
* The original code takes **34** seconds on my machine.
* A `for` loop ([FlorianH's answer](https://stackoverflow.com/a/1984904/239657)) with `+=` and `xrange()` takes **21**.
* Putting the whole thing in a function reduces it to **9** seconds! ... | Python is not particularly fast at numeric computations and I'm sure it's slower than perl when it comes to text processing.
Since you're an experienced Perl hand, I don't know if this applies to you but Python programs in the long run tend to be more maintainable and are quicker to develop. The speed is 'enough' for... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | All this micro benchmarking can get a bit silly!
For eg. just switching to `for` in both Python & Perl provides an hefty speed bump. The original Perl example would be twice as quick if `for` was used:
```
my $j = 0;
for my $i (1..100000000) {
++$j;
}
print $j;
```
And I can shave off a bit more with this:
`... | >
> is Python really that much slower than
> Perl?
>
>
>
Look at the **Computer Language Benchmarks Game** - "Compare the performance of ≈30 programming languages using ≈12 flawed benchmarks and ≈1100 programs".
They are only tiny benchmark programs but they still do a lot more than the code snippet you have tim... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | Python runs very fast, if you use the correct syntax of the python language. It is roughly described as "[pythonic](http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0)".
If you restructure your code like this, it will run at least twice as fast (well, it does on my machine):
```
j = 0
for i in range(10000000):
... | python is slower then perl. It may be faster to develop but it doesnt execute faster here is one benchmark <http://xodian.net/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html> -edit- a terrible benchmark but it is at least a real benchmark with numbers and not some guess. To bad theres... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | Python runs very fast, if you use the correct syntax of the python language. It is roughly described as "[pythonic](http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0)".
If you restructure your code like this, it will run at least twice as fast (well, it does on my machine):
```
j = 0
for i in range(10000000):
... | >
> is Python really that much slower than
> Perl?
>
>
>
Look at the **Computer Language Benchmarks Game** - "Compare the performance of ≈30 programming languages using ≈12 flawed benchmarks and ≈1100 programs".
They are only tiny benchmark programs but they still do a lot more than the code snippet you have tim... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | Python maintains global variables in a dictionary. Therefore, each time there is an assignment, the interpreter performs a **lookup on the module dictionary**, that is somewhat expensive, and this is the reason why you found your example so slower.
In order to improve performance, you should use local allocation, like... | python is slower then perl. It may be faster to develop but it doesnt execute faster here is one benchmark <http://xodian.net/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html> -edit- a terrible benchmark but it is at least a real benchmark with numbers and not some guess. To bad theres... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | The nit-picking answer is that you should compare it to idiomatic Python:
* The original code takes **34** seconds on my machine.
* A `for` loop ([FlorianH's answer](https://stackoverflow.com/a/1984904/239657)) with `+=` and `xrange()` takes **21**.
* Putting the whole thing in a function reduces it to **9** seconds! ... | I'm not up-to-date on everything with Python, but my first idea about this benchmark was the difference between Perl and Python numbers. In Perl, we have numbers. They aren't objects, and their precision is limited to the sizes imposed by the architecture. In Python, we have objects with arbitrary precision. For small ... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | The nit-picking answer is that you should compare it to idiomatic Python:
* The original code takes **34** seconds on my machine.
* A `for` loop ([FlorianH's answer](https://stackoverflow.com/a/1984904/239657)) with `+=` and `xrange()` takes **21**.
* Putting the whole thing in a function reduces it to **9** seconds! ... | All this micro benchmarking can get a bit silly!
For eg. just switching to `for` in both Python & Perl provides an hefty speed bump. The original Perl example would be twice as quick if `for` was used:
```
my $j = 0;
for my $i (1..100000000) {
++$j;
}
print $j;
```
And I can shave off a bit more with this:
`... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | Python is not particularly fast at numeric computations and I'm sure it's slower than perl when it comes to text processing.
Since you're an experienced Perl hand, I don't know if this applies to you but Python programs in the long run tend to be more maintainable and are quicker to develop. The speed is 'enough' for... | I'm not up-to-date on everything with Python, but my first idea about this benchmark was the difference between Perl and Python numbers. In Perl, we have numbers. They aren't objects, and their precision is limited to the sizes imposed by the architecture. In Python, we have objects with arbitrary precision. For small ... |
1,984,871 | I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I ... | 2009/12/31 | [
"https://Stackoverflow.com/questions/1984871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/241470/"
] | python is slower then perl. It may be faster to develop but it doesnt execute faster here is one benchmark <http://xodian.net/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html> -edit- a terrible benchmark but it is at least a real benchmark with numbers and not some guess. To bad theres... | >
> is Python really that much slower than
> Perl?
>
>
>
Look at the **Computer Language Benchmarks Game** - "Compare the performance of ≈30 programming languages using ≈12 flawed benchmarks and ≈1100 programs".
They are only tiny benchmark programs but they still do a lot more than the code snippet you have tim... |
25,100,309 | I have a memory constraint of 4GB RAM. I need to have 2.5 GB of data in RAM in order to perform further things
```
import numpy
a = numpy.random.rand(1000000,100)## This needs to be in memory
b= numpy.random.rand(1,100)
c= a-b #this need to be in code in order to perform next operation
d = numpy.linalg.norm(numpy.asar... | 2014/08/02 | [
"https://Stackoverflow.com/questions/25100309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3413239/"
] | If the creation of `a` doesn't cause a memory problem, and you don't need to preserve the values in `a`, you could compute `c` by modifying `a` in place:
```
a -= b # Now use `a` instead of `c`.
```
Otherwise, the idea of working in smaller chunks or batches is a good one. With your list comprehension solution, you... | If memory is the reason your code is slowing down and crashing why not just use a generator instead of list comprehension?
d =(numpy.sqrt(numpy.dot(i-b,i-b)) for i in a)
A generator essentially provides steps to get the next object in an iterator. In other words no operation is made and no data is stored until you ca... |
72,177,222 | Description.
------------
While trying to use pre-commit hooks, I am experiencing some difficulties, including [the latest Lava-nc release by Intel in `.tar.gz` format](https://github.com/lava-nc/lava/releases/download/v0.3.0/lava-nc-0.3.0.tar.gz) `pip` package in a Conda environment.
MWE
---
The following Conda `en... | 2022/05/09 | [
"https://Stackoverflow.com/questions/72177222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7437143/"
] | this is unfortunately a known bug in `conda` -- though I'm unfamiliar with the status on it. they're mistakenly shipping a `python3.1` binary as the default executable (it should be called `python3.10` -- they have a [2020](https://github.com/asottile/flake8-2020) problem that's probably a `sys.version[:3]` somewhere)
... | There was a ticked opened regarding the observation in pre-commit repository <https://github.com/pre-commit/pre-commit/issues/1375>
One of pre-commit contributers suggest to use `language_version: python3` for black config in `.pre-commit-config.yaml`
```yaml
repo: https://github.com/psf/black
rev: 22.3.0
hoo... |
29,224,447 | I have a python function that takes a imported module as a parameter:
```
def printModule(module):
print("That module is named '%s'" % magic(module))
import foo.bar.baz
printModule(foo.bar.baz)
```
What I want is to be able to extract the module name (in this case `foo.bar.baz`) from a passed reference to the m... | 2015/03/24 | [
"https://Stackoverflow.com/questions/29224447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/268006/"
] | The `__name__` attribute seems to work:
```
def magic(m):
return m.__name__
``` | If you have a string with the module name, you can use pkgutil.
```
import pkgutil
pkg = pkgutil.get_loader(module_name)
print pkg.fullname
```
From the module itself,
```
import pkgutil
pkg = pkgutil.get_loader(module.__name__)
print pkg.fullname
``` |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | This is quite common, in any largish system. You can use Valgrind's [suppression system](http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles) to explicitly suppress warnings that you're not interested in. | There is another option I found. James Henstridge has custom build of python which can detect the fact that python running under valgrind and in this case pymalloc allocator is disabled, with PyObject\_Malloc/PyObject\_Free passing through to normal malloc/free, which valgrind knows how to track.
Package available her... |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | The most correct option is to tell Valgrind that it should intercept Python's allocation functions.
You should patch valgrind/coregrind/m\_replacemalloc/vg\_replace\_malloc.c adding the new interceptors for PyObject\_Malloc, PyObject\_Free, PyObject\_Realloc, e.g.:
```
ALLOC_or_NULL(NONE, PyObject_Mal... | This is quite NORMAL If you want to use Valgrind more effectively and catch even more
memory leaks, you will need to configure python --without-pymalloc. <https://svn.python.org/projects/python/trunk/Misc/README.valgrind> |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | You could try using the [suppression file](http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp) that comes with the python source
Reading the [Python Valgrind README](http://svn.python.org/projects/python/trunk/Misc/README.valgrind) is a good idea too! | This is quite common, in any largish system. You can use Valgrind's [suppression system](http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles) to explicitly suppress warnings that you're not interested in. |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | This is quite common, in any largish system. You can use Valgrind's [suppression system](http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles) to explicitly suppress warnings that you're not interested in. | This is quite NORMAL If you want to use Valgrind more effectively and catch even more
memory leaks, you will need to configure python --without-pymalloc. <https://svn.python.org/projects/python/trunk/Misc/README.valgrind> |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | The most correct option is to tell Valgrind that it should intercept Python's allocation functions.
You should patch valgrind/coregrind/m\_replacemalloc/vg\_replace\_malloc.c adding the new interceptors for PyObject\_Malloc, PyObject\_Free, PyObject\_Realloc, e.g.:
```
ALLOC_or_NULL(NONE, PyObject_Mal... | There is another option I found. James Henstridge has custom build of python which can detect the fact that python running under valgrind and in this case pymalloc allocator is disabled, with PyObject\_Malloc/PyObject\_Free passing through to normal malloc/free, which valgrind knows how to track.
Package available her... |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | Following links given by Nick I was able to find some updates on [README.valgrind](https://github.com/python/cpython/blob/master/Misc/README.valgrind). In one word, for Python > 3.6, you can set `PYTHONMALLOC=malloc` environment variable to effectively disable the warnings. For example, in my machine:
```
export PYTHO... | Yes, this is typical. Large systems often leave memory un-freed, which is fine so long as it is a constant amount, and not proportional to the running history of the system. The Python interpreter falls into this category.
Perhaps you can filter the valgrind output to focus only on allocations made in your C extension... |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | You could try using the [suppression file](http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp) that comes with the python source
Reading the [Python Valgrind README](http://svn.python.org/projects/python/trunk/Misc/README.valgrind) is a good idea too! | This is quite NORMAL If you want to use Valgrind more effectively and catch even more
memory leaks, you will need to configure python --without-pymalloc. <https://svn.python.org/projects/python/trunk/Misc/README.valgrind> |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | Following links given by Nick I was able to find some updates on [README.valgrind](https://github.com/python/cpython/blob/master/Misc/README.valgrind). In one word, for Python > 3.6, you can set `PYTHONMALLOC=malloc` environment variable to effectively disable the warnings. For example, in my machine:
```
export PYTHO... | The most correct option is to tell Valgrind that it should intercept Python's allocation functions.
You should patch valgrind/coregrind/m\_replacemalloc/vg\_replace\_malloc.c adding the new interceptors for PyObject\_Malloc, PyObject\_Free, PyObject\_Realloc, e.g.:
```
ALLOC_or_NULL(NONE, PyObject_Mal... |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | Following links given by Nick I was able to find some updates on [README.valgrind](https://github.com/python/cpython/blob/master/Misc/README.valgrind). In one word, for Python > 3.6, you can set `PYTHONMALLOC=malloc` environment variable to effectively disable the warnings. For example, in my machine:
```
export PYTHO... | There is another option I found. James Henstridge has custom build of python which can detect the fact that python running under valgrind and in this case pymalloc allocator is disabled, with PyObject\_Malloc/PyObject\_Free passing through to normal malloc/free, which valgrind knows how to track.
Package available her... |
1,519,276 | I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:
```
valgrind python -c ""
```
Valgrind output full of repeated info like this:
```
==12317== Invalid read of size 4
==12317=... | 2009/10/05 | [
"https://Stackoverflow.com/questions/1519276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65736/"
] | This is quite common, in any largish system. You can use Valgrind's [suppression system](http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles) to explicitly suppress warnings that you're not interested in. | The most correct option is to tell Valgrind that it should intercept Python's allocation functions.
You should patch valgrind/coregrind/m\_replacemalloc/vg\_replace\_malloc.c adding the new interceptors for PyObject\_Malloc, PyObject\_Free, PyObject\_Realloc, e.g.:
```
ALLOC_or_NULL(NONE, PyObject_Mal... |
32,553,827 | ---I am on Ubuntu---
I am trying to setup Django Crispy forms and getting the following error:
```
Exception Type: TemplateDoesNotExist
Exception Value:
bootstrap3/layout/buttonholder.html
```
Settings.py template setup
==========================
```
TEMPLATES = [
{
'BACKEND': 'django.template.back... | 2015/09/13 | [
"https://Stackoverflow.com/questions/32553827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5054204/"
] | `ButtonHolder` isn't part of the Bootstrap template pack. It's documented as not being so.
See [this issue for discussion](https://github.com/maraujop/django-crispy-forms/issues/478)
Best bet is to use `FormActions` instead | Where do you currently save your static content. The issue seems to be due to Django's inability to find your static content from bootstrap. |
55,910,797 | Hello I've started using python fairly recently. I'm having so much trouble with this one segment of my code that gives me a keyerror when I try to remove an element from my set:
tiles.remove(m)
KeyError: 'B9'
EDIT: I forgot to mention that the m value changes everytime I call another function before the for loop. Al... | 2019/04/29 | [
"https://Stackoverflow.com/questions/55910797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8817267/"
] | You have a loop
```
for d in domain[m].copy():
```
where you are trying to `tiles.remove(m)` in every iteration. After it's removed in the first iteration, the dictionary won't have the key any more and you would get a keyerror in subsequent iterations. | The ‘remove’ statement needs to be included in the ‘if’ statement, otherwise it is never prevented. |
47,870,297 | I have a list with tuples in it looking like this:
```
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
```
I'd like to iterate over `my_list[3]` and copy the rest so I would get n lists looking like this:
```
(u'code', u'some... | 2017/12/18 | [
"https://Stackoverflow.com/questions/47870297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6139149/"
] | You can achieve this using simple tuple concatenation with `+`:
```
nlists = [my_list[:-1] + tpl for tpl in my_list[-1]]
[(u'code', u'somet text', u'integer', u'1', u'text1'),
(u'code', u'somet text', u'integer', u'2', u'text2'),
(u'code', u'somet text', u'integer', u'3', u'text3'),
(u'code', u'somet text', u'inte... | Firstly unpack your tuple:
`a,b,c,d = my_list`
This, of course, assumes 4 elements exactly to your tuple or you'll get an exception.
Then iterate over d:
`for d1,d2 in d:
print('({},{},{},{},{})'.format(a,b,c,d1,d2))` |
47,870,297 | I have a list with tuples in it looking like this:
```
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
```
I'd like to iterate over `my_list[3]` and copy the rest so I would get n lists looking like this:
```
(u'code', u'some... | 2017/12/18 | [
"https://Stackoverflow.com/questions/47870297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6139149/"
] | You can achieve this using simple tuple concatenation with `+`:
```
nlists = [my_list[:-1] + tpl for tpl in my_list[-1]]
[(u'code', u'somet text', u'integer', u'1', u'text1'),
(u'code', u'somet text', u'integer', u'2', u'text2'),
(u'code', u'somet text', u'integer', u'3', u'text3'),
(u'code', u'somet text', u'inte... | You can just iterate over and join them with the `operator+`:
```
fixed = my_list[:3] # this becomes (u'code', u'somet text', u'integer')
new_list = [fixed + x for x in my_list[3]] # list comprehension to build new list
```
You must be careful in your terminology. You call your variable `my_list` but the `()` around... |
47,870,297 | I have a list with tuples in it looking like this:
```
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
```
I'd like to iterate over `my_list[3]` and copy the rest so I would get n lists looking like this:
```
(u'code', u'some... | 2017/12/18 | [
"https://Stackoverflow.com/questions/47870297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6139149/"
] | You can achieve this using simple tuple concatenation with `+`:
```
nlists = [my_list[:-1] + tpl for tpl in my_list[-1]]
[(u'code', u'somet text', u'integer', u'1', u'text1'),
(u'code', u'somet text', u'integer', u'2', u'text2'),
(u'code', u'somet text', u'integer', u'3', u'text3'),
(u'code', u'somet text', u'inte... | You can try this:
```
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
new_list = [(my_list[0], my_list[1], my_list[2], i[0], i[-1]) for i in my_list[3:][0]]
``` |
47,870,297 | I have a list with tuples in it looking like this:
```
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
```
I'd like to iterate over `my_list[3]` and copy the rest so I would get n lists looking like this:
```
(u'code', u'some... | 2017/12/18 | [
"https://Stackoverflow.com/questions/47870297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6139149/"
] | You can achieve this using simple tuple concatenation with `+`:
```
nlists = [my_list[:-1] + tpl for tpl in my_list[-1]]
[(u'code', u'somet text', u'integer', u'1', u'text1'),
(u'code', u'somet text', u'integer', u'2', u'text2'),
(u'code', u'somet text', u'integer', u'3', u'text3'),
(u'code', u'somet text', u'inte... | You could also try this:
```
from itertools import repeat
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
result = [x + y for x, y in zip(repeat(my_list[:3], len(my_list[3])), my_list[3])]
print(result)
```
Which outputs:
... |
47,870,297 | I have a list with tuples in it looking like this:
```
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
```
I'd like to iterate over `my_list[3]` and copy the rest so I would get n lists looking like this:
```
(u'code', u'some... | 2017/12/18 | [
"https://Stackoverflow.com/questions/47870297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6139149/"
] | You can achieve this using simple tuple concatenation with `+`:
```
nlists = [my_list[:-1] + tpl for tpl in my_list[-1]]
[(u'code', u'somet text', u'integer', u'1', u'text1'),
(u'code', u'somet text', u'integer', u'2', u'text2'),
(u'code', u'somet text', u'integer', u'3', u'text3'),
(u'code', u'somet text', u'inte... | You can also try without loop and in just one line without importing any external module or complex logic , Here is lambda approach :
```
my_list = (u'code', u'somet text', u'integer', [(u'1', u'text1'), (u'2', u'text2'), (u'3', u'text3'), (u'4', u'text4'), (u'5', u'text5')])
print((list(map(lambda v:list(map(lambda ... |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | In Python for compare by not equal need `!=`, not `<>`.
So need:
```
def mape_vectorized_v2(a, b):
mask = a != 0
return (np.fabs(a - b)/a)[mask].mean()
```
Another solution from [stats.stackexchange](https://stats.stackexchange.com/a/294069):
```
def mean_absolute_percentage_error(y_true, y_pred):
y_... | Here is an improved version that is mindful of Zero:
```
#Mean Absolute Percentage error
def mape(y_true, y_pred,sample_weight=None,multioutput='uniform_average'):
y_type, y_true, y_pred, multioutput = _check_reg_targets(y_true, y_pred, multioutput)
epsilon = np.finfo(np.float64).eps
mape = np.abs(y_p... |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | In Python for compare by not equal need `!=`, not `<>`.
So need:
```
def mape_vectorized_v2(a, b):
mask = a != 0
return (np.fabs(a - b)/a)[mask].mean()
```
Another solution from [stats.stackexchange](https://stats.stackexchange.com/a/294069):
```
def mean_absolute_percentage_error(y_true, y_pred):
y_... | Here is another way to calculate MAPE which can tackle '0' denominator and it is fast.
```py
def mod_my_MAPE(y, pred):
y = y[:][y[:]!=0]
pred = pred[:][y[:]!=0]
summ = np.sum(abs((y[:] - pred[:])/y[:]))
return summ/len(y)
``` |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | Both solutions are not working with zero values. This is working form me:
```
def percentage_error(actual, predicted):
res = np.empty(actual.shape)
for j in range(actual.shape[0]):
if actual[j] != 0:
res[j] = (actual[j] - predicted[j]) / actual[j]
else:
res[j] = predicte... | Since `scikit-learn` version 0.24. one is able to use [`sklearn.metrics.mean_absolute_percentage_error`](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_percentage_error.html).
[Here](https://github.com/scikit-learn/scikit-learn/blob/46f15a00d2324da4b9f12c9168ddda8dddb1b607/sklearn/metr... |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | Both solutions are not working with zero values. This is working form me:
```
def percentage_error(actual, predicted):
res = np.empty(actual.shape)
for j in range(actual.shape[0]):
if actual[j] != 0:
res[j] = (actual[j] - predicted[j]) / actual[j]
else:
res[j] = predicte... | Here is an improved version that is mindful of Zero:
```
#Mean Absolute Percentage error
def mape(y_true, y_pred,sample_weight=None,multioutput='uniform_average'):
y_type, y_true, y_pred, multioutput = _check_reg_targets(y_true, y_pred, multioutput)
epsilon = np.finfo(np.float64).eps
mape = np.abs(y_p... |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | Both solutions are not working with zero values. This is working form me:
```
def percentage_error(actual, predicted):
res = np.empty(actual.shape)
for j in range(actual.shape[0]):
if actual[j] != 0:
res[j] = (actual[j] - predicted[j]) / actual[j]
else:
res[j] = predicte... | Here is another way to calculate MAPE which can tackle '0' denominator and it is fast.
```py
def mod_my_MAPE(y, pred):
y = y[:][y[:]!=0]
pred = pred[:][y[:]!=0]
summ = np.sum(abs((y[:] - pred[:])/y[:]))
return summ/len(y)
``` |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | The new version of scikit-learn (v0.24) has a function that will calculate MAPE.
`sklearn.metrics.mean_absolute_percentage_error`
All what you need is two array-like variables: `y_true` storing the actual/real values, and `y_pred` storing the predicted values.
You can refer to the official documentation [here](https:... | Here is another way to calculate MAPE which can tackle '0' denominator and it is fast.
```py
def mod_my_MAPE(y, pred):
y = y[:][y[:]!=0]
pred = pred[:][y[:]!=0]
summ = np.sum(abs((y[:] - pred[:])/y[:]))
return summ/len(y)
``` |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | In Python for compare by not equal need `!=`, not `<>`.
So need:
```
def mape_vectorized_v2(a, b):
mask = a != 0
return (np.fabs(a - b)/a)[mask].mean()
```
Another solution from [stats.stackexchange](https://stats.stackexchange.com/a/294069):
```
def mean_absolute_percentage_error(y_true, y_pred):
y_... | Since `scikit-learn` version 0.24. one is able to use [`sklearn.metrics.mean_absolute_percentage_error`](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_percentage_error.html).
[Here](https://github.com/scikit-learn/scikit-learn/blob/46f15a00d2324da4b9f12c9168ddda8dddb1b607/sklearn/metr... |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | The new version of scikit-learn (v0.24) has a function that will calculate MAPE.
`sklearn.metrics.mean_absolute_percentage_error`
All what you need is two array-like variables: `y_true` storing the actual/real values, and `y_pred` storing the predicted values.
You can refer to the official documentation [here](https:... | Here is an improved version that is mindful of Zero:
```
#Mean Absolute Percentage error
def mape(y_true, y_pred,sample_weight=None,multioutput='uniform_average'):
y_type, y_true, y_pred, multioutput = _check_reg_targets(y_true, y_pred, multioutput)
epsilon = np.finfo(np.float64).eps
mape = np.abs(y_p... |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | The new version of scikit-learn (v0.24) has a function that will calculate MAPE.
`sklearn.metrics.mean_absolute_percentage_error`
All what you need is two array-like variables: `y_true` storing the actual/real values, and `y_pred` storing the predicted values.
You can refer to the official documentation [here](https:... | Since the actual values can also be zeroes I am taking the average of the actual values in the denominator, instead of the actual values:
```py
Error = np.sum(np.abs(np.subtract(data_4['y'],data_4['pred'])))
Average = np.sum(data_4['y'])
MAPE = Error/Average
``` |
47,648,133 | I want to calculate Mean Absolute percentage error (MAPE) of predicted and true values. I found a solution from [here](https://stackoverflow.com/questions/42250958/how-to-optimize-mape-code-in-python), but this gives error and shows invalid syntax in the line `mask = a <> 0`
```
def mape_vectorized_v2(a, b):
... | 2017/12/05 | [
"https://Stackoverflow.com/questions/47648133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7972408/"
] | In Python for compare by not equal need `!=`, not `<>`.
So need:
```
def mape_vectorized_v2(a, b):
mask = a != 0
return (np.fabs(a - b)/a)[mask].mean()
```
Another solution from [stats.stackexchange](https://stats.stackexchange.com/a/294069):
```
def mean_absolute_percentage_error(y_true, y_pred):
y_... | Both solutions are not working with zero values. This is working form me:
```
def percentage_error(actual, predicted):
res = np.empty(actual.shape)
for j in range(actual.shape[0]):
if actual[j] != 0:
res[j] = (actual[j] - predicted[j]) / actual[j]
else:
res[j] = predicte... |
52,135,293 | I'm following the `Quickstart` on <https://developers.google.com/drive/api/v3/quickstart/python>. I've enabled the drive API through the page, loaded the **credentials.json** and can successfully list files in my google drive. However when I wanted to download a file, I got the message
```
`The user has not granted t... | 2018/09/02 | [
"https://Stackoverflow.com/questions/52135293",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1767754/"
] | Once you go through the `Quick-Start Tutorial` initially the Scope is given as:
```
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
```
So after listing files and you decide to download, it won't work as you need to generate the the token again, so changing scope won't recreate or prompt you for ... | I ran into the same error. I authorized the entire scope, then retrieved the file, and use the io.Base class to stream the data into a file. Note, you'll need to create the file first.
```
from __future__ import print_function
from googleapiclient.discovery import build
import io
from apiclient import http
from googl... |
52,135,293 | I'm following the `Quickstart` on <https://developers.google.com/drive/api/v3/quickstart/python>. I've enabled the drive API through the page, loaded the **credentials.json** and can successfully list files in my google drive. However when I wanted to download a file, I got the message
```
`The user has not granted t... | 2018/09/02 | [
"https://Stackoverflow.com/questions/52135293",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1767754/"
] | Once you go through the `Quick-Start Tutorial` initially the Scope is given as:
```
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
```
So after listing files and you decide to download, it won't work as you need to generate the the token again, so changing scope won't recreate or prompt you for ... | **Delete token.pickle and re-run program.**
Elaboration:- Once you run Quickstart Example, It stores a token.pickle.
Thereafter, even if you change the scope in google api console and add the following the scope in your code :-
```
SCOPES = ['https://www.googleapis.com/auth/drive']
```
It will not work until you d... |
52,135,293 | I'm following the `Quickstart` on <https://developers.google.com/drive/api/v3/quickstart/python>. I've enabled the drive API through the page, loaded the **credentials.json** and can successfully list files in my google drive. However when I wanted to download a file, I got the message
```
`The user has not granted t... | 2018/09/02 | [
"https://Stackoverflow.com/questions/52135293",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1767754/"
] | I ran into the same error. I authorized the entire scope, then retrieved the file, and use the io.Base class to stream the data into a file. Note, you'll need to create the file first.
```
from __future__ import print_function
from googleapiclient.discovery import build
import io
from apiclient import http
from googl... | **Delete token.pickle and re-run program.**
Elaboration:- Once you run Quickstart Example, It stores a token.pickle.
Thereafter, even if you change the scope in google api console and add the following the scope in your code :-
```
SCOPES = ['https://www.googleapis.com/auth/drive']
```
It will not work until you d... |
48,634,071 | I'm very new to python, so please bear with me. I'm having trouble to visualize an excel/csv file with seaborn's lmplot. This code:
```
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
df=pd.read_csv("C:/Users/me/Documents/Jupyter Notebooks/Seaborn/Test.csv")
sns.set_style('... | 2018/02/06 | [
"https://Stackoverflow.com/questions/48634071",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9319446/"
] | ```
sns.lmplot(x=df["TestX"],y=df["TestY"], data=df)
```
x, y : strings, optional
Input variables, these should be column names in data.
You can try again with:
```
sns.lmplot(x="TestX",y="TestY", data=df)
``` | ```
import pandas as pd
import numpy as np
import matplotlib
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(style="darkgrid")
df = pd.read_csv('data.csv')
sns.lmplot(x="Duration", y="Maxpulse", data=df)
plt.show()
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()
```
"Duration" and "Maxpluse"... |
57,624,731 | I would like to assert that two dictionaries are equal, using Python's [`unittest`](https://docs.python.org/3/library/unittest.html), but ignoring the values of certain keys in the dictionary, in a convenient syntax, like this:
```py
from unittest import TestCase
class Example(TestCase):
def test_example(self):
... | 2019/08/23 | [
"https://Stackoverflow.com/questions/57624731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/247696/"
] | There is [`unittest.mock.ANY`](https://docs.python.org/3/library/unittest.mock.html#any) which compares equal to everything.
```
from unittest import TestCase
import unittest.mock as mock
class Example(TestCase):
def test_happy_path(self):
result = {
"name": "John Smith",
"year_of_... | You can simply ignore the selected keys in the `result` dictionary.
```
self.assertEqual({k: v for k, v in result.items()
if k not in ('image_url', 'unique_id')},
{"name": "John Smith",
"year_of_birth": 1980})
``` |
62,155,242 | I'm trying to compile a python script with sklearn, pandas, numpy and igraph, but the Pyinstaller executable doesn't run correctly because it can't find version.json in tmp folder.
```
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Usuario\\AppData\\Local\\Temp\\_MEI106882\\wcwidth\\version.json'
... | 2020/06/02 | [
"https://Stackoverflow.com/questions/62155242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11902728/"
] | You'll need to include the `wcwidth` project directory in your data since it isn't considered a package or a module, its a data file.
In your spec file:
```
...
import wcwidth
a = Analysis(['main.py'],
pathex=[],
binaries=[],
datas=[
(os.path.dirname(wcwidth._... | I hit this issue when creating a binary from a virtual environment. It seems installing ipython within the virtual environment is causing this.
Recreating a new virtual environment without ipython seems to overcome the issue. |
58,308,911 | 1) I first map the key names to a dictionary called main\_dict with an empty list (the actual problem has many keys hence the reason why I am doing this)
2) I then loop over a data matrix consisting of 3 columns
3) When I append a value to a column (the key) in the dictionary, the data is appended to wrong keys.
Whe... | 2019/10/09 | [
"https://Stackoverflow.com/questions/58308911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6685541/"
] | Without using numpy (which is a heavy weight package for what you are doing) I would do this:
```
keys = ["A", "B", "C"]
main_dict = {key: [] for key in keys}
data = [[2018, 1.1, 3.3], [2017, 2.1, 5.4], [2016, 3.1, 1.4]]
# since you are reading from a file
for datum in data:
for index, key in enumerate(keys):
... | The problem is in
```
main_dict = main_dict.fromkeys(key_names, val)
```
The same list val is referenced by all the keys since python passes reference. |
42,585,598 | When I try to deploy to my Elastic Beanstalk environment I am getting this python error. Everything was working fine a few days ago.
```
$ eb deploy
ERROR: AttributeError :: 'NoneType' object has no attribute 'split'
```
I've thus far attempted to update everything to no effect by issuing the following commands:
``... | 2017/03/03 | [
"https://Stackoverflow.com/questions/42585598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2767129/"
] | I had the same issue. Turns out that when you enable CodeCommit the CLI looks for a remote called "codecommit-origin" and if you don't have a git remote with that *specific* name it will throw that error.
Posting this for anyone else who stumbles upon the same issue. | I fixed this with `eb codesource local && eb deploy`, so it forgets about CodeCommit. |
42,585,598 | When I try to deploy to my Elastic Beanstalk environment I am getting this python error. Everything was working fine a few days ago.
```
$ eb deploy
ERROR: AttributeError :: 'NoneType' object has no attribute 'split'
```
I've thus far attempted to update everything to no effect by issuing the following commands:
``... | 2017/03/03 | [
"https://Stackoverflow.com/questions/42585598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2767129/"
] | I had the same issue. Turns out that when you enable CodeCommit the CLI looks for a remote called "codecommit-origin" and if you don't have a git remote with that *specific* name it will throw that error.
Posting this for anyone else who stumbles upon the same issue. | To fix this error I needed to add the following lines to my `.elasticbeanstalk/config.yml`
`branch-defaults:
master:
environment: prod-api
group_suffix: null
staging:
environment: staging-api
group_suffix: null`
You'll need to change the branch names and environments to what is applicable to your case (in our ... |
42,585,598 | When I try to deploy to my Elastic Beanstalk environment I am getting this python error. Everything was working fine a few days ago.
```
$ eb deploy
ERROR: AttributeError :: 'NoneType' object has no attribute 'split'
```
I've thus far attempted to update everything to no effect by issuing the following commands:
``... | 2017/03/03 | [
"https://Stackoverflow.com/questions/42585598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2767129/"
] | I fixed this with `eb codesource local && eb deploy`, so it forgets about CodeCommit. | To fix this error I needed to add the following lines to my `.elasticbeanstalk/config.yml`
`branch-defaults:
master:
environment: prod-api
group_suffix: null
staging:
environment: staging-api
group_suffix: null`
You'll need to change the branch names and environments to what is applicable to your case (in our ... |
36,051,751 | I am trying to sort 4 integers input by the user into numerical order using only the min() and max() functions in python. I can get the highest and lowest number easily, but cannot work out a combination to order the two middle numbers? Does anyone have an idea? | 2016/03/17 | [
"https://Stackoverflow.com/questions/36051751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6074977/"
] | So I'm guessing your input is something like this?
```
string = input('Type your numbers, separated by a space')
```
Then I'd do:
```
numbers = [int(i) for i in string.strip().split(' ')]
amount_of_numbers = len(numbers)
sorted = []
for i in range(amount_of_numbers):
x = max(numbers)
numbers.remove(x)
s... | LITERALLY just min and max? Odd, but, why not. I'm about to crash, but I think the following would work:
```
# Easy
arr[0] = max(a,b,c,d)
# Take the smallest element from each pair.
#
# You will never take the largest element from the set, but since one of the
# pairs will be (largest, second_largest) you will at so... |
36,051,751 | I am trying to sort 4 integers input by the user into numerical order using only the min() and max() functions in python. I can get the highest and lowest number easily, but cannot work out a combination to order the two middle numbers? Does anyone have an idea? | 2016/03/17 | [
"https://Stackoverflow.com/questions/36051751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6074977/"
] | So I'm guessing your input is something like this?
```
string = input('Type your numbers, separated by a space')
```
Then I'd do:
```
numbers = [int(i) for i in string.strip().split(' ')]
amount_of_numbers = len(numbers)
sorted = []
for i in range(amount_of_numbers):
x = max(numbers)
numbers.remove(x)
s... | I have worked it out.
```
min_integer = min(first_integer, second_integer, third_integer, fourth_integer)
mid_low_integer = min(max(first_integer, second_integer), max(third_integer, fourth_integer))
mid_high_integer = max(min(first_integer, second_integer), min(third_integer, fourth_integer))
max_integer = max(first_... |
36,051,751 | I am trying to sort 4 integers input by the user into numerical order using only the min() and max() functions in python. I can get the highest and lowest number easily, but cannot work out a combination to order the two middle numbers? Does anyone have an idea? | 2016/03/17 | [
"https://Stackoverflow.com/questions/36051751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6074977/"
] | So I'm guessing your input is something like this?
```
string = input('Type your numbers, separated by a space')
```
Then I'd do:
```
numbers = [int(i) for i in string.strip().split(' ')]
amount_of_numbers = len(numbers)
sorted = []
for i in range(amount_of_numbers):
x = max(numbers)
numbers.remove(x)
s... | For Tankerbuzz's result for the following:
```
first_integer = 9
second_integer = 19
third_integer = 1
fourth_integer = 15
```
I get 1, 15, 9, 19 as the ascending values.
The following is one of the forms that gives symbolic form of the ascending values (using i1-i4 instead of first\_integer, etc...):
```
Min(i1, ... |
36,051,751 | I am trying to sort 4 integers input by the user into numerical order using only the min() and max() functions in python. I can get the highest and lowest number easily, but cannot work out a combination to order the two middle numbers? Does anyone have an idea? | 2016/03/17 | [
"https://Stackoverflow.com/questions/36051751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6074977/"
] | LITERALLY just min and max? Odd, but, why not. I'm about to crash, but I think the following would work:
```
# Easy
arr[0] = max(a,b,c,d)
# Take the smallest element from each pair.
#
# You will never take the largest element from the set, but since one of the
# pairs will be (largest, second_largest) you will at so... | I have worked it out.
```
min_integer = min(first_integer, second_integer, third_integer, fourth_integer)
mid_low_integer = min(max(first_integer, second_integer), max(third_integer, fourth_integer))
mid_high_integer = max(min(first_integer, second_integer), min(third_integer, fourth_integer))
max_integer = max(first_... |
36,051,751 | I am trying to sort 4 integers input by the user into numerical order using only the min() and max() functions in python. I can get the highest and lowest number easily, but cannot work out a combination to order the two middle numbers? Does anyone have an idea? | 2016/03/17 | [
"https://Stackoverflow.com/questions/36051751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6074977/"
] | For Tankerbuzz's result for the following:
```
first_integer = 9
second_integer = 19
third_integer = 1
fourth_integer = 15
```
I get 1, 15, 9, 19 as the ascending values.
The following is one of the forms that gives symbolic form of the ascending values (using i1-i4 instead of first\_integer, etc...):
```
Min(i1, ... | I have worked it out.
```
min_integer = min(first_integer, second_integer, third_integer, fourth_integer)
mid_low_integer = min(max(first_integer, second_integer), max(third_integer, fourth_integer))
mid_high_integer = max(min(first_integer, second_integer), min(third_integer, fourth_integer))
max_integer = max(first_... |
29,989,956 | I want to share a variable value between a function defined within a python class and an externally defined function. So in the code below, when the internalCompute() function is called, self.data is updated. How can I access this updated data value inside a function that is defined outside the class, i.e inside the re... | 2015/05/01 | [
"https://Stackoverflow.com/questions/29989956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1833722/"
] | >
> determine the physical size of an iPhone (in inches)
>
>
>
This will never be possible, because the physical screen is made up of *pixels* (square LEDs), and there is no way to ask the size of one of those.
Thus, for example, an app that presents a ruler (inches / centimetres) would need to know *in some othe... | I'm using this code im my pch file:
```
#define IS_IPAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
#define IS_IPHONE6PLUS (!IS_IPAD && [[UIScreen mainScreen] bounds].size.height >= 736)
#define IS_IPHONE6 (!IS_IPAD && !IS_PHONE6PLUS && [[UIScreen mainScreen] bounds].size.height >= 667)
... |
49,901,249 | I have searched everywhere for how to fix this and I could not find anything, so I'm sorry if there is already a thread existing on this issue. Also, I'm fairly new to Linux, GDP, and StackOverflow, this is my first post.
First, I am running on Debian GNU/Linux 9 (stretch) with the Windows subsystem for Linux and when... | 2018/04/18 | [
"https://Stackoverflow.com/questions/49901249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9664285/"
] | When you build the project it generates .war file as you know.You can extract it and find all the dependent jar files at {.war}\WEB-INF\lib\ | My suggestion is, go to C:\Users\<>.m2\repository (your maven directory) and search \*.jar...it will list out all the jars in the window.
Copy all the jars and paste in your directory. |
34,295,670 | I have a problem with a litlle program in python:
what I want is to write on a archive called text numbers from 0 to 10, but the program give me error all the time and doesn't print anything.
```
i=0
while(i<11):
outfile = open('text.txt', 'a')
outfile.write('\n'+i)
outfile.close()
i=i+1
```
I tried... | 2015/12/15 | [
"https://Stackoverflow.com/questions/34295670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5631254/"
] | I'm guessing that the error you're getting involves concatenating a string with an integer.
try:
```
outfile.write(str(i) + '\n')
``` | Assuming you want a file that looks like this:
```
1
2
3
4
5
6
7
8
9
```
Did you try it this way?
```
>>> fo = open('outfile.txt', 'w')
>>> for i in range(1,10):
... fo.write(str(i)+"\n")
>>> fo.close()
```
The error you probably are getting is this :
>
> TypeError: unsupported operand type(s) for +: 'int'... |
34,295,670 | I have a problem with a litlle program in python:
what I want is to write on a archive called text numbers from 0 to 10, but the program give me error all the time and doesn't print anything.
```
i=0
while(i<11):
outfile = open('text.txt', 'a')
outfile.write('\n'+i)
outfile.close()
i=i+1
```
I tried... | 2015/12/15 | [
"https://Stackoverflow.com/questions/34295670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5631254/"
] | You're openning/closing your file at each iteration of while-loop. Why overdo things? You can easily do the job, once the file is open.
Also, you try to write *'\n'* (which is a string) plus *i* (which is an integer). That's wrong, and you need to convert your *i* into string too.
Try this code:
```
with open('text... | Assuming you want a file that looks like this:
```
1
2
3
4
5
6
7
8
9
```
Did you try it this way?
```
>>> fo = open('outfile.txt', 'w')
>>> for i in range(1,10):
... fo.write(str(i)+"\n")
>>> fo.close()
```
The error you probably are getting is this :
>
> TypeError: unsupported operand type(s) for +: 'int'... |
34,295,670 | I have a problem with a litlle program in python:
what I want is to write on a archive called text numbers from 0 to 10, but the program give me error all the time and doesn't print anything.
```
i=0
while(i<11):
outfile = open('text.txt', 'a')
outfile.write('\n'+i)
outfile.close()
i=i+1
```
I tried... | 2015/12/15 | [
"https://Stackoverflow.com/questions/34295670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5631254/"
] | I'm guessing that the error you're getting involves concatenating a string with an integer.
try:
```
outfile.write(str(i) + '\n')
``` | Try:
```
while(i<11):
outfile = open('text.txt', 'a')
outfile.write('\n'+str(i))
outfile.close()
i=i+1
```
I am getting a text.txt with 0-10 on seperate lines with a blank line at the top. |
34,295,670 | I have a problem with a litlle program in python:
what I want is to write on a archive called text numbers from 0 to 10, but the program give me error all the time and doesn't print anything.
```
i=0
while(i<11):
outfile = open('text.txt', 'a')
outfile.write('\n'+i)
outfile.close()
i=i+1
```
I tried... | 2015/12/15 | [
"https://Stackoverflow.com/questions/34295670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5631254/"
] | You're openning/closing your file at each iteration of while-loop. Why overdo things? You can easily do the job, once the file is open.
Also, you try to write *'\n'* (which is a string) plus *i* (which is an integer). That's wrong, and you need to convert your *i* into string too.
Try this code:
```
with open('text... | I'm guessing that the error you're getting involves concatenating a string with an integer.
try:
```
outfile.write(str(i) + '\n')
``` |
34,295,670 | I have a problem with a litlle program in python:
what I want is to write on a archive called text numbers from 0 to 10, but the program give me error all the time and doesn't print anything.
```
i=0
while(i<11):
outfile = open('text.txt', 'a')
outfile.write('\n'+i)
outfile.close()
i=i+1
```
I tried... | 2015/12/15 | [
"https://Stackoverflow.com/questions/34295670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5631254/"
] | You're openning/closing your file at each iteration of while-loop. Why overdo things? You can easily do the job, once the file is open.
Also, you try to write *'\n'* (which is a string) plus *i* (which is an integer). That's wrong, and you need to convert your *i* into string too.
Try this code:
```
with open('text... | Try:
```
while(i<11):
outfile = open('text.txt', 'a')
outfile.write('\n'+str(i))
outfile.close()
i=i+1
```
I am getting a text.txt with 0-10 on seperate lines with a blank line at the top. |
45,860,272 | My goal is to run a Python script that uses Anaconda libraries (such as Pandas) on `Azure WebJob` but can't seem to figure out how to load the libraries.
I start out just by testing a simple Azure blob to blob file copy which works when run locally but hit into an error `"ImportError: No module named 'azure'"` when ra... | 2017/08/24 | [
"https://Stackoverflow.com/questions/45860272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6329714/"
] | It seems like you've kown about deployment of Azure WebJobs, I offer the below steps for you to show how to load external libraries in python scripts.
Step 1 :
Use the **virtualenv** component to create an independent python runtime environment in your system.Please install it first with command `pip install virtualen... | You can point your Azure WebJob to your main WebApp environment (and thus its real site packages). This allows you to use the newest fastest version of Python supported by the WebApp (right now mine is 364x64), much better than 3.4 or 2.7 in x86. Another huge benefit is then you don't have to maintain an additional set... |
59,103,401 | I am currently implementing a MINLP optimization problem in Python GEKKO for determining the optimal operational strategy of a trigeneration energy system. As I consider the energy demand during all periods of different representative days as input data, basically all my decision variables, intermediates, etc. are 2D a... | 2019/11/29 | [
"https://Stackoverflow.com/questions/59103401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12456060/"
] | Extra square brackets are needed for 2D list definition. This gives a 2D list with 3 rows and 4 columns.
```py
[[p+10*z for p in range(3)] for z in range(4)]
# Result: [[0, 1, 2], [10, 11, 12], [20, 21, 22], [30, 31, 32]]
```
If you leave out the inner brackets, it is a 1D list of length 12.
```py
[p+10*z for p in ... | To diagnose the problem, I added a call to open the run folder before the solve command.
```py
#_____Solve Problem_____
m.open_folder()
m.solve()
```
I opened the `gk_model0.apm` model file with a text editor to look at a text version of the model. At the bottom it shows that there are problems with the last two int... |
42,329,346 | I am trying to learn Cloudformation im stuck with a senario where I need a second EC2 instance started after one EC2 is provisioned and good to go.
This is what i have in UserData of Instance one
```
"#!/bin/bash\n",
"#############################################################################################\n",
"s... | 2017/02/19 | [
"https://Stackoverflow.com/questions/42329346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/907937/"
] | The first thing I notice is that you have two `GET`s, instead of a `GET` and then a `POST` (as you noticed yourself).
But let's assume the HTML form is correct, since it works in development. That makes me suspect there is some Javascript that is throwing things off. One common problem when moving things from develop... | I am no expert but since your code is working on local just try the following to get an idea where the problem might be:
a) Run production environment on your local, see if the problem persists there.
b) Try to test run without any javascript enabled or atleast disable custom ones on the production server.
c) Try to... |
42,329,346 | I am trying to learn Cloudformation im stuck with a senario where I need a second EC2 instance started after one EC2 is provisioned and good to go.
This is what i have in UserData of Instance one
```
"#!/bin/bash\n",
"#############################################################################################\n",
"s... | 2017/02/19 | [
"https://Stackoverflow.com/questions/42329346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/907937/"
] | This sounds like an SSL issue to me.
Your form is definitely POSTing to the route. You can confirm this by adding `data-remote="true"` to your form HTML in the browser, then watching the console as you make the request:
```
XHR finished loading: POST "https://win-marketing.sciencesupercrew.com/en/users/login"
```
W... | The first thing I notice is that you have two `GET`s, instead of a `GET` and then a `POST` (as you noticed yourself).
But let's assume the HTML form is correct, since it works in development. That makes me suspect there is some Javascript that is throwing things off. One common problem when moving things from develop... |
42,329,346 | I am trying to learn Cloudformation im stuck with a senario where I need a second EC2 instance started after one EC2 is provisioned and good to go.
This is what i have in UserData of Instance one
```
"#!/bin/bash\n",
"#############################################################################################\n",
"s... | 2017/02/19 | [
"https://Stackoverflow.com/questions/42329346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/907937/"
] | Glad you figured it out! Posting my last comment as an answer below.
Thanks for the live example. So, I click on the submit button and I can see the browser sending a POST request. The server responds successfully, but with a redirect.
`POST https://win-marketing.sciencesupercrew.com/en/users/login` -> `301 Moved Per... | The first thing I notice is that you have two `GET`s, instead of a `GET` and then a `POST` (as you noticed yourself).
But let's assume the HTML form is correct, since it works in development. That makes me suspect there is some Javascript that is throwing things off. One common problem when moving things from develop... |
42,329,346 | I am trying to learn Cloudformation im stuck with a senario where I need a second EC2 instance started after one EC2 is provisioned and good to go.
This is what i have in UserData of Instance one
```
"#!/bin/bash\n",
"#############################################################################################\n",
"s... | 2017/02/19 | [
"https://Stackoverflow.com/questions/42329346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/907937/"
] | This sounds like an SSL issue to me.
Your form is definitely POSTing to the route. You can confirm this by adding `data-remote="true"` to your form HTML in the browser, then watching the console as you make the request:
```
XHR finished loading: POST "https://win-marketing.sciencesupercrew.com/en/users/login"
```
W... | I am no expert but since your code is working on local just try the following to get an idea where the problem might be:
a) Run production environment on your local, see if the problem persists there.
b) Try to test run without any javascript enabled or atleast disable custom ones on the production server.
c) Try to... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.