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
1,312,524
I'm attempting to build a webpage that loads depending on the input provided. I'm having some trouble wrapping my head around event handling in javascript, basically. Coming from python, if I wanted to wait for a specific keyboard input before moving on to the next object to display, I would create a *while* loop and p...
2009/08/21
[ "https://Stackoverflow.com/questions/1312524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/160854/" ]
In JavaScript, you give up control of the main loop. The browser runs the main loop and calls back down into your code when an event or timeout/interval occurs. You have to handle the event and then return so that the browser can get on with doing other things, firing events, and so on. So you cannot have a ‘listening...
``` document.onkeydown = function(e) { //do what you need to do } ``` That's all it takes in javascript. You don't need to loop to wait for the event to happen, whenever the event occurs that function will be called, which in turn can call other functions, do whatever needs to be be done. Think of it as that instea...
1,312,524
I'm attempting to build a webpage that loads depending on the input provided. I'm having some trouble wrapping my head around event handling in javascript, basically. Coming from python, if I wanted to wait for a specific keyboard input before moving on to the next object to display, I would create a *while* loop and p...
2009/08/21
[ "https://Stackoverflow.com/questions/1312524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/160854/" ]
you should not use such loops in javascript. basically you do not want to block the browser from doing its job. Thus you work with events (onkeyup/down). also instead of a loop you should use setTimeout if you want to wait a little and continue if something happened you can do sth like that: ``` <html> <script> var ...
``` document.onkeydown = function(e) { //do what you need to do } ``` That's all it takes in javascript. You don't need to loop to wait for the event to happen, whenever the event occurs that function will be called, which in turn can call other functions, do whatever needs to be be done. Think of it as that instea...
1,312,524
I'm attempting to build a webpage that loads depending on the input provided. I'm having some trouble wrapping my head around event handling in javascript, basically. Coming from python, if I wanted to wait for a specific keyboard input before moving on to the next object to display, I would create a *while* loop and p...
2009/08/21
[ "https://Stackoverflow.com/questions/1312524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/160854/" ]
In JavaScript, you give up control of the main loop. The browser runs the main loop and calls back down into your code when an event or timeout/interval occurs. You have to handle the event and then return so that the browser can get on with doing other things, firing events, and so on. So you cannot have a ‘listening...
Check out the YUI key listener <http://developer.yahoo.com/yui/docs/YAHOO.util.KeyListener.html> using the key listener, YUI takes care of capturing any events. IN javascript, there will almost never be an instance where you must wait in a while loop for something to happen. If you need examples of how event handlin...
1,312,524
I'm attempting to build a webpage that loads depending on the input provided. I'm having some trouble wrapping my head around event handling in javascript, basically. Coming from python, if I wanted to wait for a specific keyboard input before moving on to the next object to display, I would create a *while* loop and p...
2009/08/21
[ "https://Stackoverflow.com/questions/1312524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/160854/" ]
For easier implementation of event handling I recommend you to use a library such as [Prototype](http://www.prototypejs.org/api/event) or [Jquery](http://docs.jquery.com/Events) (Note that both links take you to their respective Event handling documentation. In order to use them you have to keep in mind 3 things: * W...
Check out the YUI key listener <http://developer.yahoo.com/yui/docs/YAHOO.util.KeyListener.html> using the key listener, YUI takes care of capturing any events. IN javascript, there will almost never be an instance where you must wait in a while loop for something to happen. If you need examples of how event handlin...
1,312,524
I'm attempting to build a webpage that loads depending on the input provided. I'm having some trouble wrapping my head around event handling in javascript, basically. Coming from python, if I wanted to wait for a specific keyboard input before moving on to the next object to display, I would create a *while* loop and p...
2009/08/21
[ "https://Stackoverflow.com/questions/1312524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/160854/" ]
In JavaScript, you give up control of the main loop. The browser runs the main loop and calls back down into your code when an event or timeout/interval occurs. You have to handle the event and then return so that the browser can get on with doing other things, firing events, and so on. So you cannot have a ‘listening...
For easier implementation of event handling I recommend you to use a library such as [Prototype](http://www.prototypejs.org/api/event) or [Jquery](http://docs.jquery.com/Events) (Note that both links take you to their respective Event handling documentation. In order to use them you have to keep in mind 3 things: * W...
1,312,524
I'm attempting to build a webpage that loads depending on the input provided. I'm having some trouble wrapping my head around event handling in javascript, basically. Coming from python, if I wanted to wait for a specific keyboard input before moving on to the next object to display, I would create a *while* loop and p...
2009/08/21
[ "https://Stackoverflow.com/questions/1312524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/160854/" ]
you should not use such loops in javascript. basically you do not want to block the browser from doing its job. Thus you work with events (onkeyup/down). also instead of a loop you should use setTimeout if you want to wait a little and continue if something happened you can do sth like that: ``` <html> <script> var ...
you could attach an event listener to the window object like this ``` window.captureEvents(Event.KEYPRESS); window.onkeypress = output; function output(event) { alert("you pressed" + event.which); } ```
41,596,143
I am trying to find an elegant way to calculate a bivariate normal CDF with python where one upper bound of the CDF is a function of two variables, of which one is a variable of the bivariate normal density (integral variable). Example: ``` from scipy import integrate import numpy as np # First define f(x, y) as the...
2017/01/11
[ "https://Stackoverflow.com/questions/41596143", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3023486/" ]
Although it's slow this approach seems to work. The first few lines, up to 'this should produce 1', are a sanity check. I wanted to verify that my approach would correctly calculate the volume under the density. It does. I use a variance-covariance matrix to get the desired correlation of 0.4 and avoid writing my own...
I had to write an option model that was using a bivariate distribution in Python. However, I did not find a prebuilt function that was fast - some seem to be using the random scipy generator to emulate it with the multivariate function. BUT... if you really dig deep and see what the other financial packages are using, ...
47,784,693
I am not able to handle to pass optional parameters in python `**kwargs` ``` def ExecuteyourQuery(self, queryStatement, *args, **kwargs): if self.cursorOBJ is not None: resultOBJ = self.cursorOBJ.execute(queryStatement, *args,**kwargs) self.resultsVal = resultOBJ.fetchall() ``` --- The below stateme...
2017/12/13
[ "https://Stackoverflow.com/questions/47784693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4949381/" ]
When using args as the last parameter of your function, you can pass any number of **arguments** after the formal arguments, when existing. Args is a [tuple](https://www.tutorialspoint.com/python/python_tuples.htm). ``` def my_method(farg, *args): print('FARG: ', farg) print('ARGS: ', args) my_method('Formal Argu...
another way to do this is by setting a default value for a parameter ``` def method(one, two, three=3): print(one) print(two) if three != 3: # don't have to use it like this but it is a default value print(three) ``` this set a default value if the parameter is not filled if it is filled it will over...
28,750,643
okay, im a new guy at all this, just randomly picked it up with my neighbor and we are both stuck at this. We have been following this tutorial([here](http://www.swaroopch.com/notes/python/#intro)) and have made it to 6.6 in the tutorial. I have searched the forums looking for a way to get passed my problem but all the...
2015/02/26
[ "https://Stackoverflow.com/questions/28750643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4611612/" ]
First of all, Python shell differs from system shell (cmd.exe). You try to run `python script.py` in Python interpreter instead of `cmd.exe`. Open `cmd.exe` and type in `python script.py` to solve this. It'll run fine if it doesn't contain any errors. `cd c:\\` doesn't work due to the same reason. First `quit()` or...
You are in the python interpreter which is an interactive shell. You can consider it "scratch paper" to test out or try different things. To run your script : quit() in the command prompt run python.exe hello.py ( on windows.. on \*nix just python)
74,158,560
I am going through JavaScript course on freecodecamp and I came across this ['Steamroller' challenge](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller). Coming from python I really like one-liner solutions so I managed to write one for this challe...
2022/10/21
[ "https://Stackoverflow.com/questions/74158560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14625103/" ]
Quote from [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat#description): > > Then, for each argument, its value will be concatenated into the array — for normal objects or primitives, the argument itself will become an element of the final array; **for arrays ..., e...
So others answer your question, but here are simplified code ```js const steamrollArray1 = arr => Array.isArray(arr) ? [].concat(...arr.map(steamrollArray1)) : arr; const steamrollArray2 = arr => Array.isArray(arr) ? arr.flat(Infinity) : arr; console.log( steamrollArray1([1, [2], [3, [[4]]]]) ); // returns [1, 2, ...
74,158,560
I am going through JavaScript course on freecodecamp and I came across this ['Steamroller' challenge](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller). Coming from python I really like one-liner solutions so I managed to write one for this challe...
2022/10/21
[ "https://Stackoverflow.com/questions/74158560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14625103/" ]
`Array.prototype.concat`'s arguments, if they are arrays, are essentially flattened into the resulting array. So ``` [2].concat(3, [4, 5]) ``` results in `[2, 3, 4, 5]`. Similarly ``` [].concat(3, [4, 5]) ``` results in `[3, 4, 5]`. But spreading an array into another array does not perform such flattening on *e...
So others answer your question, but here are simplified code ```js const steamrollArray1 = arr => Array.isArray(arr) ? [].concat(...arr.map(steamrollArray1)) : arr; const steamrollArray2 = arr => Array.isArray(arr) ? arr.flat(Infinity) : arr; console.log( steamrollArray1([1, [2], [3, [[4]]]]) ); // returns [1, 2, ...
48,946,036
I'm getting started with docker compose and have been working through the simple demo flask application. The thing is, I'm running this from inside of an organization that intercepts all communication in such a way that SSL errors are thrown right and left. They provide us with three root certificates we need to instal...
2018/02/23
[ "https://Stackoverflow.com/questions/48946036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3929175/" ]
This isn't really a docker-specific question: you are asking, in effect, "how do I install certificate authorities under Linux"? The answer is going to be the same regardless of whether you are running your ssl client inside or outside of a container. Your Python image is based on alpine, and alpine uses the "ca-certi...
In my case, Host machine's MTU is 1450, and Docker's MTU is 1500. Which causes docker set MSS to 1460, and then TLS "server hello" packet got bigger than 1450 bytes, so the Host machine discard it. To see if it's your case too, run ifconfig on both you Docker container and your host machine. If Host's MTU is less tha...
48,946,036
I'm getting started with docker compose and have been working through the simple demo flask application. The thing is, I'm running this from inside of an organization that intercepts all communication in such a way that SSL errors are thrown right and left. They provide us with three root certificates we need to instal...
2018/02/23
[ "https://Stackoverflow.com/questions/48946036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3929175/" ]
This isn't really a docker-specific question: you are asking, in effect, "how do I install certificate authorities under Linux"? The answer is going to be the same regardless of whether you are running your ssl client inside or outside of a container. Your Python image is based on alpine, and alpine uses the "ca-certi...
I was trying to read data from an API in my Go code and I was facing similar ssl error: ``` x509: certificate signed by unknown authority ``` My container was based on `debian:stretch` which is really really small ~100MB. This happens when `ca-certificates` are not installed. I installed `ca-certificates` (which al...
48,946,036
I'm getting started with docker compose and have been working through the simple demo flask application. The thing is, I'm running this from inside of an organization that intercepts all communication in such a way that SSL errors are thrown right and left. They provide us with three root certificates we need to instal...
2018/02/23
[ "https://Stackoverflow.com/questions/48946036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3929175/" ]
In my case, I must add in my Dockerfile these sentences: ``` COPY company.crt /usr/local/share/ca-certificates/company.crt RUN update-ca-certificates ... RUN pip install --cert /etc/ssl/certs/company.pem -r requirements.txt ``` You need the certificate of your company in .crt format. When docker execute update-ca-ce...
In my case, Host machine's MTU is 1450, and Docker's MTU is 1500. Which causes docker set MSS to 1460, and then TLS "server hello" packet got bigger than 1450 bytes, so the Host machine discard it. To see if it's your case too, run ifconfig on both you Docker container and your host machine. If Host's MTU is less tha...
48,946,036
I'm getting started with docker compose and have been working through the simple demo flask application. The thing is, I'm running this from inside of an organization that intercepts all communication in such a way that SSL errors are thrown right and left. They provide us with three root certificates we need to instal...
2018/02/23
[ "https://Stackoverflow.com/questions/48946036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3929175/" ]
In my case, I must add in my Dockerfile these sentences: ``` COPY company.crt /usr/local/share/ca-certificates/company.crt RUN update-ca-certificates ... RUN pip install --cert /etc/ssl/certs/company.pem -r requirements.txt ``` You need the certificate of your company in .crt format. When docker execute update-ca-ce...
I was trying to read data from an API in my Go code and I was facing similar ssl error: ``` x509: certificate signed by unknown authority ``` My container was based on `debian:stretch` which is really really small ~100MB. This happens when `ca-certificates` are not installed. I installed `ca-certificates` (which al...
48,946,036
I'm getting started with docker compose and have been working through the simple demo flask application. The thing is, I'm running this from inside of an organization that intercepts all communication in such a way that SSL errors are thrown right and left. They provide us with three root certificates we need to instal...
2018/02/23
[ "https://Stackoverflow.com/questions/48946036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3929175/" ]
In my case, Host machine's MTU is 1450, and Docker's MTU is 1500. Which causes docker set MSS to 1460, and then TLS "server hello" packet got bigger than 1450 bytes, so the Host machine discard it. To see if it's your case too, run ifconfig on both you Docker container and your host machine. If Host's MTU is less tha...
I was trying to read data from an API in my Go code and I was facing similar ssl error: ``` x509: certificate signed by unknown authority ``` My container was based on `debian:stretch` which is really really small ~100MB. This happens when `ca-certificates` are not installed. I installed `ca-certificates` (which al...
32,866,578
I am trying to bastardise Django and Django REST Framework into a single module so see if it can work. So far, I have the following code: ``` ############################################################################### # SETTINGS ############################################################################### import...
2015/09/30
[ "https://Stackoverflow.com/questions/32866578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
If you are using `docker run` to start your container, you have the `--add-host=""` argument which takes a hostname and an IP that get written to the container's `/etc/hosts`. Your startup command would look like this: ``` docker run -d --add-host="domain-a.dev:192.168.0.10" [...] ``` Replace `192.168.0.10` with ...
I basically worked around this now by using <http://xip.io/> By using urls like `sub.127.0.0.1.xip.io` I can connect to my local machine. My app only has to know that `127.0.0.1.xip.io` is treated as the "top level domain", and `sub` is the domain name without tld. (In a Ruby on Rails app this can be done by adjusting...
69,920,403
There is an HTML page that I would like to find the elements of two input types and press one button to log in with the help of selenium along with python3. The problem is that I can't seem to find a way of doing this correctly. The two texts and the button are in a form without an id or some tag, also I'm new on this...
2021/11/10
[ "https://Stackoverflow.com/questions/69920403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1089615/" ]
I just changed your code from `presence_of_element_located` expected conditions to `presence_of_element_located`, corrected the locators and make some more things clearer. I hope now this should work. ```py from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by...
To click on the link *`Login to start working`*, next key in the credentials and finally to click on the *Submit* button you can use the following [Locator Strategies](https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890): ``` driver.get("http://example.com/") We...
69,920,403
There is an HTML page that I would like to find the elements of two input types and press one button to log in with the help of selenium along with python3. The problem is that I can't seem to find a way of doing this correctly. The two texts and the button are in a form without an id or some tag, also I'm new on this...
2021/11/10
[ "https://Stackoverflow.com/questions/69920403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1089615/" ]
I found a solution by doing the above and worked: ``` self.driver.find_element(By.XPATH, "//div[@class='login-box d-flex justify-content-between " "align-items-center']//input[@placeholder='Email']").send_keys( '[email protected]') ``` The above can be done as well fo...
To click on the link *`Login to start working`*, next key in the credentials and finally to click on the *Submit* button you can use the following [Locator Strategies](https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890): ``` driver.get("http://example.com/") We...
34,126,957
I'm trying to install Pygame for python 3.5 32bit. I have learned that I can open the `.whl` files provided on the site by using the `pip` command. The problem is I've tried multiple ways doing this but with constant error. ``` python -m pip install pygame-1.9.2a0-cp35-none-win32.whl 'python' is not recognized as an ...
2015/12/07
[ "https://Stackoverflow.com/questions/34126957", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5481774/" ]
It would be helpful if your filtered the result set from the database by the customer's name, for example... ``` DefaultListModel dlm = new DefaultListModel(); try (PreparedStatement st = con.prepareStatement("select songpick from customer where customername=?")) { String customerName = (String)jComboBox1.getSelec...
You need to have a `WHERE` clause and set the value that you want to get from E.g. `SELECT songpick FROM customer WHERE <columnName> = ?` and set the value of the that you need before the `executeQuery` statement with `st.setString(1, "Foo");`
72,207,311
``` #!/bin/bash data_dir=./all for file_name in "$data_dir"/* do echo "$file_name" python process.py "$file_name" done ``` For example, this script processes the files sequentially in a directory in a 'for' loop. Is it possible to start multiple process.py instances to process...
2022/05/11
[ "https://Stackoverflow.com/questions/72207311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3943868/" ]
It's better to use [os.listdir](https://docs.python.org/3/library/os.html#os.listdir) and [subprocess.Popen](https://stackoverflow.com/a/7224186/5707560) to start new processes.
With **GNU Parallel**, like this: ``` parallel python process.py {} ::: all/* ``` It will run N jobs in parallel, where N is the number of CPU cores you have, or you can specify `-j4` to run on just 4, for example. Many, many options for: * logging, * splitting/chunking inputs, * tagging/separating output, * stagg...
72,207,311
``` #!/bin/bash data_dir=./all for file_name in "$data_dir"/* do echo "$file_name" python process.py "$file_name" done ``` For example, this script processes the files sequentially in a directory in a 'for' loop. Is it possible to start multiple process.py instances to process...
2022/05/11
[ "https://Stackoverflow.com/questions/72207311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3943868/" ]
I have another possibility for you, if still needed. It uses the `screen` command to create a new detached process with the supplied command. Here is an example: ```sh #!/bin/bash data_dir=./all for file_name in "$data_dir"/* do echo "$file_name" screen -dm python process.py "$file_name" done ```
With **GNU Parallel**, like this: ``` parallel python process.py {} ::: all/* ``` It will run N jobs in parallel, where N is the number of CPU cores you have, or you can specify `-j4` to run on just 4, for example. Many, many options for: * logging, * splitting/chunking inputs, * tagging/separating output, * stagg...
17,694,780
I'm a front-end dev struggling along with Django. I have the basics pretty much down but I've hit at wall at the following point. I have a site running locally and also on a dev machine. Locally I've added an extra class model to an already existing app, registered it in the relevant admin.py and checked it in the set...
2013/07/17
[ "https://Stackoverflow.com/questions/17694780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2321623/" ]
I figured out the problem. Turns out the login I was using to get into the admin didn't have superuser privileges. So I made a new one with: ``` python manage.py createsuperuser ``` After logging in with the new username and password I could see all my new shiny tables!
Are you sure touching `.wsgi` file does restart your app? It looks like it doesn't. Make sure the app is restarted. Find the evidence touching `.wsgi` file restarts the app maybe. Since you don't provide any insight about how the dev server runs the apps, we won't be able to help you any further.
54,172,462
I'm new to ML and Colab. Trying to play around with the project at <https://github.com/tkarras/progressive_growing_of_gans> but having a hard time getting it running in Colab. When I run the import\_example.py script from the project, I get immediate errors relating to Tensorflow not loading. So I tried stepping back ...
2019/01/13
[ "https://Stackoverflow.com/questions/54172462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1958417/" ]
Even I was facing the same issue. Later I realized I forgot to enable **GPU** in notebook settings. I enabled it and installed **TensorFlow-GPU** (GPU version). You can find notebook settings in **Edit** > **Notebook Settings**. [Here's the screenshot](https://i.stack.imgur.com/Sr7Hr.jpg)
You just have to read the error carefully: > > NOTE: If your import is failing due to a missing package, you can > manually install dependencies using either !pip or !apt. > > > Try running: ``` !pip install tensorflow ``` inside notebook, and then rerun the cell with the import.
54,172,462
I'm new to ML and Colab. Trying to play around with the project at <https://github.com/tkarras/progressive_growing_of_gans> but having a hard time getting it running in Colab. When I run the import\_example.py script from the project, I get immediate errors relating to Tensorflow not loading. So I tried stepping back ...
2019/01/13
[ "https://Stackoverflow.com/questions/54172462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1958417/" ]
Check if you have installed the version of tensorflow that you need in Colab or not?! (Maybe you have installed a different version of tensorflow-gpu and you have not installed the corresponding tensorflow version. I got the same error in this case) ``` !pip list ``` If you do not have tensorflow in the list, you sh...
You just have to read the error carefully: > > NOTE: If your import is failing due to a missing package, you can > manually install dependencies using either !pip or !apt. > > > Try running: ``` !pip install tensorflow ``` inside notebook, and then rerun the cell with the import.
54,172,462
I'm new to ML and Colab. Trying to play around with the project at <https://github.com/tkarras/progressive_growing_of_gans> but having a hard time getting it running in Colab. When I run the import\_example.py script from the project, I get immediate errors relating to Tensorflow not loading. So I tried stepping back ...
2019/01/13
[ "https://Stackoverflow.com/questions/54172462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1958417/" ]
Even I was facing the same issue. Later I realized I forgot to enable **GPU** in notebook settings. I enabled it and installed **TensorFlow-GPU** (GPU version). You can find notebook settings in **Edit** > **Notebook Settings**. [Here's the screenshot](https://i.stack.imgur.com/Sr7Hr.jpg)
TensorFlow is included by default in Colab. So, I suspect you've somehow broken the existing install. You can request a new backend by selecting the Runtime -> Reset all runtimes... menu. Then, try `import tensorflow as tf` again.
54,172,462
I'm new to ML and Colab. Trying to play around with the project at <https://github.com/tkarras/progressive_growing_of_gans> but having a hard time getting it running in Colab. When I run the import\_example.py script from the project, I get immediate errors relating to Tensorflow not loading. So I tried stepping back ...
2019/01/13
[ "https://Stackoverflow.com/questions/54172462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1958417/" ]
Check if you have installed the version of tensorflow that you need in Colab or not?! (Maybe you have installed a different version of tensorflow-gpu and you have not installed the corresponding tensorflow version. I got the same error in this case) ``` !pip list ``` If you do not have tensorflow in the list, you sh...
TensorFlow is included by default in Colab. So, I suspect you've somehow broken the existing install. You can request a new backend by selecting the Runtime -> Reset all runtimes... menu. Then, try `import tensorflow as tf` again.
54,172,462
I'm new to ML and Colab. Trying to play around with the project at <https://github.com/tkarras/progressive_growing_of_gans> but having a hard time getting it running in Colab. When I run the import\_example.py script from the project, I get immediate errors relating to Tensorflow not loading. So I tried stepping back ...
2019/01/13
[ "https://Stackoverflow.com/questions/54172462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1958417/" ]
Even I was facing the same issue. Later I realized I forgot to enable **GPU** in notebook settings. I enabled it and installed **TensorFlow-GPU** (GPU version). You can find notebook settings in **Edit** > **Notebook Settings**. [Here's the screenshot](https://i.stack.imgur.com/Sr7Hr.jpg)
Check if you have installed the version of tensorflow that you need in Colab or not?! (Maybe you have installed a different version of tensorflow-gpu and you have not installed the corresponding tensorflow version. I got the same error in this case) ``` !pip list ``` If you do not have tensorflow in the list, you sh...
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
``` l=[1,1,2,3,3,3,5,6] [x for x in l if l.count(x) > 1] [1, 1, 3, 3, 3] ``` Adds elements that appear at least twice in your list. In your own code you need to change the line `for x in data` to `for x in data[:]:` Using `data[:]` you are iterating over a `copy` of original list.
Another linear solution. ``` >>> data = [1, 1, 2, 3, 3, 3, 5, 6] >>> D = dict.fromkeys(data, 0) >>> for item in data: ... D[item] += 1 ... >>> [item for item in data if D[item] > 1] [1, 1, 3, 3, 3] ```
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
There is a linear time solution for that: ``` def tester(data): cnt = {} for e in data: cnt[e] = cnt.get(e, 0) + 1 return [x for x in data if cnt[x] > 1] ```
You shouldn't remove items from a mutable list while iterating over that same list. The interpreter doesn't have any way to keep track of where it is in the list while you're doing this. See [this question](//stackoverflow.com/questions/1207406/remove-items-from-a-list-while-iterating-in-python) for another example of...
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
Another linear solution. ``` >>> data = [1, 1, 2, 3, 3, 3, 5, 6] >>> D = dict.fromkeys(data, 0) >>> for item in data: ... D[item] += 1 ... >>> [item for item in data if D[item] > 1] [1, 1, 3, 3, 3] ```
You shouldn't remove items from a mutable list while iterating over that same list. The interpreter doesn't have any way to keep track of where it is in the list while you're doing this. See [this question](//stackoverflow.com/questions/1207406/remove-items-from-a-list-while-iterating-in-python) for another example of...
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
``` l=[1,1,2,3,3,3,5,6] [x for x in l if l.count(x) > 1] [1, 1, 3, 3, 3] ``` Adds elements that appear at least twice in your list. In your own code you need to change the line `for x in data` to `for x in data[:]:` Using `data[:]` you are iterating over a `copy` of original list.
you can use the list comprehention,just like this: ``` def tester(data): return [x for x in data if data.count(x) != 1] ``` it is not recommended to remove item when iterating
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
``` l=[1,1,2,3,3,3,5,6] [x for x in l if l.count(x) > 1] [1, 1, 3, 3, 3] ``` Adds elements that appear at least twice in your list. In your own code you need to change the line `for x in data` to `for x in data[:]:` Using `data[:]` you are iterating over a `copy` of original list.
There is a linear time solution for that: ``` def tester(data): cnt = {} for e in data: cnt[e] = cnt.get(e, 0) + 1 return [x for x in data if cnt[x] > 1] ```
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
This is occurring because you are removing from a list as you're iterating through it. Instead, consider appending to a new list. You could also use collections.Counter, if you're using 2.7 or greater: ``` [a for a, b in collections.Counter(your_list).items() if b > 1] ```
Another linear solution. ``` >>> data = [1, 1, 2, 3, 3, 3, 5, 6] >>> D = dict.fromkeys(data, 0) >>> for item in data: ... D[item] += 1 ... >>> [item for item in data if D[item] > 1] [1, 1, 3, 3, 3] ```
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
Another linear solution. ``` >>> data = [1, 1, 2, 3, 3, 3, 5, 6] >>> D = dict.fromkeys(data, 0) >>> for item in data: ... D[item] += 1 ... >>> [item for item in data if D[item] > 1] [1, 1, 3, 3, 3] ```
you can use the list comprehention,just like this: ``` def tester(data): return [x for x in data if data.count(x) != 1] ``` it is not recommended to remove item when iterating
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
This is occurring because you are removing from a list as you're iterating through it. Instead, consider appending to a new list. You could also use collections.Counter, if you're using 2.7 or greater: ``` [a for a, b in collections.Counter(your_list).items() if b > 1] ```
You shouldn't remove items from a mutable list while iterating over that same list. The interpreter doesn't have any way to keep track of where it is in the list while you're doing this. See [this question](//stackoverflow.com/questions/1207406/remove-items-from-a-list-while-iterating-in-python) for another example of...
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
``` l=[1,1,2,3,3,3,5,6] [x for x in l if l.count(x) > 1] [1, 1, 3, 3, 3] ``` Adds elements that appear at least twice in your list. In your own code you need to change the line `for x in data` to `for x in data[:]:` Using `data[:]` you are iterating over a `copy` of original list.
This is occurring because you are removing from a list as you're iterating through it. Instead, consider appending to a new list. You could also use collections.Counter, if you're using 2.7 or greater: ``` [a for a, b in collections.Counter(your_list).items() if b > 1] ```
24,253,977
I am trying to remove non repeating characters from a list in python. e.g list = [1,1,2,3,3,3,5,6] should return [1,1,3,3]. My initial attempt was: ``` def tester(data): for x in data: if data.count(x) == 1: data.remove(x) return data ``` This will work for some inputs, but for [1,2,3,4,5...
2014/06/17
[ "https://Stackoverflow.com/questions/24253977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636636/" ]
There is a linear time solution for that: ``` def tester(data): cnt = {} for e in data: cnt[e] = cnt.get(e, 0) + 1 return [x for x in data if cnt[x] > 1] ```
Another linear solution. ``` >>> data = [1, 1, 2, 3, 3, 3, 5, 6] >>> D = dict.fromkeys(data, 0) >>> for item in data: ... D[item] += 1 ... >>> [item for item in data if D[item] > 1] [1, 1, 3, 3, 3] ```
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
You could remove `0`s from the list. If the list becomes empty, return `0`, the product otherwise: ``` >>> no_zeroes = [value for value in values if value > 0] >>> no_zeroes [1.0, 3.4] >>> reduce(lambda x, y : y*x, no_zeroes) if no_zeroes else 0 3.4 ``` Note that from a mathematical point of view, the product of an ...
if you use numpy arrays you can filter out the zero values: ``` import numpy as np vals = np.array([0.0, 0.0, 0.0, 0.0]) no_zeros = vals[vals>0] if no_zeros: print( np.prod(no_zeros)) else: print(0.0) ```
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
You could remove `0`s from the list. If the list becomes empty, return `0`, the product otherwise: ``` >>> no_zeroes = [value for value in values if value > 0] >>> no_zeroes [1.0, 3.4] >>> reduce(lambda x, y : y*x, no_zeroes) if no_zeroes else 0 3.4 ``` Note that from a mathematical point of view, the product of an ...
Just filter out 0.0 values with [`filter`](https://docs.python.org/3/library/functions.html#filter) ``` from functools import reduce vals_without_zero = filter(lambda x: x, vals) reduce(lambda x, y : x * y, vals_without_zero) ```
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
You could remove `0`s from the list. If the list becomes empty, return `0`, the product otherwise: ``` >>> no_zeroes = [value for value in values if value > 0] >>> no_zeroes [1.0, 3.4] >>> reduce(lambda x, y : y*x, no_zeroes) if no_zeroes else 0 3.4 ``` Note that from a mathematical point of view, the product of an ...
Another option: ``` from functools import reduce vals = [1.0, 0.0, 3.4, 0.0] reduce(lambda x,y: y if x == 0 else (x if y == 0 else x*y), vals, 0) # 3.4 vals = [0.0, 0.0, 0.0, 0.0] reduce(lambda x,y: y if x == 0 else (x if y == 0 else x*y), vals, 0) # 0.0 ```
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
You could remove `0`s from the list. If the list becomes empty, return `0`, the product otherwise: ``` >>> no_zeroes = [value for value in values if value > 0] >>> no_zeroes [1.0, 3.4] >>> reduce(lambda x, y : y*x, no_zeroes) if no_zeroes else 0 3.4 ``` Note that from a mathematical point of view, the product of an ...
Combining `functools.reduce` (with *initiator* value `1`) and `filter` functions: ``` vals = [1.0, 0.0, 3.4, 0.0] result = functools.reduce(operator.mul, list(filter(lambda x: x>0, vals)) or [0], 1) print(result) # 3.4 ``` --- ``` vals = [0.0, 0.0, 0.0, 0.0] result = functools.reduce(operator.mul, list(filter(lam...
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
if you use numpy arrays you can filter out the zero values: ``` import numpy as np vals = np.array([0.0, 0.0, 0.0, 0.0]) no_zeros = vals[vals>0] if no_zeros: print( np.prod(no_zeros)) else: print(0.0) ```
Just filter out 0.0 values with [`filter`](https://docs.python.org/3/library/functions.html#filter) ``` from functools import reduce vals_without_zero = filter(lambda x: x, vals) reduce(lambda x, y : x * y, vals_without_zero) ```
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
if you use numpy arrays you can filter out the zero values: ``` import numpy as np vals = np.array([0.0, 0.0, 0.0, 0.0]) no_zeros = vals[vals>0] if no_zeros: print( np.prod(no_zeros)) else: print(0.0) ```
Combining `functools.reduce` (with *initiator* value `1`) and `filter` functions: ``` vals = [1.0, 0.0, 3.4, 0.0] result = functools.reduce(operator.mul, list(filter(lambda x: x>0, vals)) or [0], 1) print(result) # 3.4 ``` --- ``` vals = [0.0, 0.0, 0.0, 0.0] result = functools.reduce(operator.mul, list(filter(lam...
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
Another option: ``` from functools import reduce vals = [1.0, 0.0, 3.4, 0.0] reduce(lambda x,y: y if x == 0 else (x if y == 0 else x*y), vals, 0) # 3.4 vals = [0.0, 0.0, 0.0, 0.0] reduce(lambda x,y: y if x == 0 else (x if y == 0 else x*y), vals, 0) # 0.0 ```
Just filter out 0.0 values with [`filter`](https://docs.python.org/3/library/functions.html#filter) ``` from functools import reduce vals_without_zero = filter(lambda x: x, vals) reduce(lambda x, y : x * y, vals_without_zero) ```
45,062,219
Is there a simpler way possible to just add numbers which are regarded as strings but also integer by python? It doesn't let me add it, maybe because of the way I converted the integer to string and then a list? I have done this so far: ``` function_menu() print() numbers = str(number) lists = [] lists.extend(numbers...
2017/07/12
[ "https://Stackoverflow.com/questions/45062219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8295906/" ]
Another option: ``` from functools import reduce vals = [1.0, 0.0, 3.4, 0.0] reduce(lambda x,y: y if x == 0 else (x if y == 0 else x*y), vals, 0) # 3.4 vals = [0.0, 0.0, 0.0, 0.0] reduce(lambda x,y: y if x == 0 else (x if y == 0 else x*y), vals, 0) # 0.0 ```
Combining `functools.reduce` (with *initiator* value `1`) and `filter` functions: ``` vals = [1.0, 0.0, 3.4, 0.0] result = functools.reduce(operator.mul, list(filter(lambda x: x>0, vals)) or [0], 1) print(result) # 3.4 ``` --- ``` vals = [0.0, 0.0, 0.0, 0.0] result = functools.reduce(operator.mul, list(filter(lam...
37,622,153
I would like to compute all (different) intersections of a collection of finite sets of integers (here implemented as a list of lists) in python (to avoid confusion, a formal definition is at the end of the question): ``` > A = [[0,1,2,3],[0,1,4],[1,2,4],[2,3,4],[0,3,4]] > all_intersections(A) # desired output [[], [0...
2016/06/03
[ "https://Stackoverflow.com/questions/37622153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1442181/" ]
Here is a recursive solution. It is almost instantaneous on your test example: ``` def allIntersections(frozenSets): if len(frozenSets) == 0: return [] else: head = frozenSets[0] tail = frozenSets[1:] tailIntersections = allIntersections(tail) newIntersections = [head] ...
Iterative solution that takes about 3.5 ms on my machine for your large test input: ``` from itertools import starmap, product from operator import and_ def all_intersections(sets): # Convert to set of frozensets for uniquification/type correctness last = new = sets = set(map(frozenset, sets)) # Keep goin...
61,657,685
First project from work and got stuck with this tedious error on Ubuntu. Currently using node -v 13.8.0, installed python 2.7.17, GCC 7.5.0 also checked node-gyp npm page and installed all python and gcc dependencies. here is my package.json file ``` "dependencies": { "apn": "^2.1.5", "async": "^1.5.2", ...
2020/05/07
[ "https://Stackoverflow.com/questions/61657685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11847762/" ]
The problem you have is the **time** package which is outdated <https://www.npmjs.com/package/time>. There are some different solutions depending on why are you using that package, you could use a different library/package to handle dates and time, but you will probably need to refactor some code. Try removing this d...
This works for me ``` npm install -g npm-check-updates npm-check-updates -u npm install ```
11,067,697
I'm building a calendar-based web app, and am in great need of a javascript Date library-- something similar to python's [dateutil](http://labix.org/python-dateutil). I came across [DateJs](http://www.datejs.com/). The functionality looks great. My only hesitance is that the repo hasn't been touched since early 2008. U...
2012/06/16
[ "https://Stackoverflow.com/questions/11067697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/652693/" ]
I'd like to recommend [momentjs](http://momentjs.com/) - a very lightweight, yet surprisingly capable Date JS library. )
DateJS works wonders for us. I am not really concerned that development seems to have stalled as it is pretty complete as-is.
11,067,697
I'm building a calendar-based web app, and am in great need of a javascript Date library-- something similar to python's [dateutil](http://labix.org/python-dateutil). I came across [DateJs](http://www.datejs.com/). The functionality looks great. My only hesitance is that the repo hasn't been touched since early 2008. U...
2012/06/16
[ "https://Stackoverflow.com/questions/11067697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/652693/" ]
I'd like to recommend [momentjs](http://momentjs.com/) - a very lightweight, yet surprisingly capable Date JS library. )
Try <https://github.com/abritinthebay/datejs> , It is a forked version of <http://www.datejs.com/> It is actively maintained by new Author !
11,067,697
I'm building a calendar-based web app, and am in great need of a javascript Date library-- something similar to python's [dateutil](http://labix.org/python-dateutil). I came across [DateJs](http://www.datejs.com/). The functionality looks great. My only hesitance is that the repo hasn't been touched since early 2008. U...
2012/06/16
[ "https://Stackoverflow.com/questions/11067697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/652693/" ]
Try <https://github.com/abritinthebay/datejs> , It is a forked version of <http://www.datejs.com/> It is actively maintained by new Author !
DateJS works wonders for us. I am not really concerned that development seems to have stalled as it is pretty complete as-is.
1,314,717
In python, I can construct my [optparse](http://docs.python.org/library/optparse.html) instance such that it will automatically filter out the options and non-option/flags into two different buckets: ``` (options, args) = parser.parse_args() ``` With boost::program\_options, how do I retrieve a list of tokens which ...
2009/08/22
[ "https://Stackoverflow.com/questions/1314717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20712/" ]
IIRC, you have to use a combination of [`positional_options_description`](http://www.boost.org/doc/libs/1_39_0/doc/html/program_options/overview.html#id2892937) and [*hidden options*](http://www.boost.org/doc/libs/1_39_0/doc/html/program_options/howto.html#id2893967). The idea is to (1) add a normal option and give it ...
Here is an example: ``` namespace po = boost::program_options; po::positional_options_description m_positional; po::options_description m_cmdLine; po::variables_map m_variables; m_cmdLine.add_options() (/*stuff*/) ("input", po::value<vector<string> >()->composing(), "") ; m_positional.add("input", -1); po...
59,801,340
I have been attempting to make a small python program to monitor and return ping results from different servers. I have reached a point where pinging each device in the sequence has become inefficient and lacks performance. I want to continuously ping each one of my targets at the same time on my python. What would th...
2020/01/18
[ "https://Stackoverflow.com/questions/59801340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12737497/" ]
First of all you can't have many id's with the same value in a one html page. Cause it will result an error in the future while your doing a lot of code to it. Please change your btnedt to a class not an id. then change your script like this. ``` <script> $(document).ready(function () { $(document).on('cl...
Use class instead of multiple IDs ================================= > > Share your modal code > > > ``` var mem_butn = "<td><input type=\"button\" class=\"btnedt\" value=\"Edit\" /></td>"; ``` ``` <script> $(document).ready(function () { $('body').on('click', '.btnedt', function() { $...
61,005,152
Here I am using `fft` function of `numpy` to plot the fft of PCM wave generated from a 10000Hz sine wave. But the amplitude of the plot I am getting is wrong. The frequency is coming correct using `fftfreq` function which I am printing in the console itself. My python code is here. ``` import numpy as np import matpl...
2020/04/03
[ "https://Stackoverflow.com/questions/61005152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12673488/" ]
After a long home work I could able to find my issue. As I mentioned in the **Updating the work:** the reason was with the number of samples which I took was wrong. I changed the two lines in the code ``` n_sa = 8 * int(freq_in_hertz) t_fft = np.linspace(0, 1, n_sa) ``` to ``` n_sa = y.size //number of samples di...
I'm not sure exactly what you are trying to do, but my suspicion is that the Sine\_10000Hz.bin file isn't what you think it is. Is it possible it contains more than one channel (left & right)? Is it realy signed 16 bit integers? It's not hard to create a 10kHz sine wave in 16 bit integers in numpy. ```py import num...
61,005,152
Here I am using `fft` function of `numpy` to plot the fft of PCM wave generated from a 10000Hz sine wave. But the amplitude of the plot I am getting is wrong. The frequency is coming correct using `fftfreq` function which I am printing in the console itself. My python code is here. ``` import numpy as np import matpl...
2020/04/03
[ "https://Stackoverflow.com/questions/61005152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12673488/" ]
After a long home work I could able to find my issue. As I mentioned in the **Updating the work:** the reason was with the number of samples which I took was wrong. I changed the two lines in the code ``` n_sa = 8 * int(freq_in_hertz) t_fft = np.linspace(0, 1, n_sa) ``` to ``` n_sa = y.size //number of samples di...
I'm adding a link to a script I've build that outputs the FFT with ACTUAL amplitude (for real signals - e.g. your signal). Have a go and see if it works: `dt=1/frate` in your constellation.... <https://stackoverflow.com/a/53925342/4879610>
64,924,830
Is it possible to write an API with Python so you can connect a physical ON and OFF switch via USB to a PC and when user presses the switch to ON or OFF, the python program detects it and send a signal to a web app and shows ON or OFF message on the website? I am sorry if what I am asking its not clear enough!
2020/11/20
[ "https://Stackoverflow.com/questions/64924830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12487489/" ]
You can simply use `std::optional`: ``` String(const std::optional<int> &min_len, const std::optional<int> &max_len, const std::optional<std::string> &pattern); Type *type = new String(5, {}, std::nullptr); // last 2 parameters are omitted. ``` For C++14 you can use similar constructs that exist in other op...
Have you tried to use an [std::optional](https://en.cppreference.com/w/cpp/utility/optional) (since C++17)? I know you mentioned the need to use C++14 compatible code, but there is a [boost::optional](https://www.boost.org/doc/libs/1_65_1/libs/optional/doc/html/index.html) available.
64,924,830
Is it possible to write an API with Python so you can connect a physical ON and OFF switch via USB to a PC and when user presses the switch to ON or OFF, the python program detects it and send a signal to a web app and shows ON or OFF message on the website? I am sorry if what I am asking its not clear enough!
2020/11/20
[ "https://Stackoverflow.com/questions/64924830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12487489/" ]
You can simply use `std::optional`: ``` String(const std::optional<int> &min_len, const std::optional<int> &max_len, const std::optional<std::string> &pattern); Type *type = new String(5, {}, std::nullptr); // last 2 parameters are omitted. ``` For C++14 you can use similar constructs that exist in other op...
You can write your own class that can contain value or not if you can't use std::optional. It is not like lot of code. Can make its interface like std::optioal has or can make something different, what matters is data: ``` class OptInt { bool set_; int value_; public: OptInt() : set_(false) , value_(0) {} ...
64,924,830
Is it possible to write an API with Python so you can connect a physical ON and OFF switch via USB to a PC and when user presses the switch to ON or OFF, the python program detects it and send a signal to a web app and shows ON or OFF message on the website? I am sorry if what I am asking its not clear enough!
2020/11/20
[ "https://Stackoverflow.com/questions/64924830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12487489/" ]
You can write your own class that can contain value or not if you can't use std::optional. It is not like lot of code. Can make its interface like std::optioal has or can make something different, what matters is data: ``` class OptInt { bool set_; int value_; public: OptInt() : set_(false) , value_(0) {} ...
Have you tried to use an [std::optional](https://en.cppreference.com/w/cpp/utility/optional) (since C++17)? I know you mentioned the need to use C++14 compatible code, but there is a [boost::optional](https://www.boost.org/doc/libs/1_65_1/libs/optional/doc/html/index.html) available.
64,924,830
Is it possible to write an API with Python so you can connect a physical ON and OFF switch via USB to a PC and when user presses the switch to ON or OFF, the python program detects it and send a signal to a web app and shows ON or OFF message on the website? I am sorry if what I am asking its not clear enough!
2020/11/20
[ "https://Stackoverflow.com/questions/64924830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12487489/" ]
I lack reputation points to comment on @Kostas To be compatible with C++14 you can try experimental namespace which has optional (if it is available/works on your compiler) ``` #include <experimental/optional> ``` then you can use ``` String(std::experimental::optional<int> &min_len,.....) min_len.value_or(-1) ``...
Have you tried to use an [std::optional](https://en.cppreference.com/w/cpp/utility/optional) (since C++17)? I know you mentioned the need to use C++14 compatible code, but there is a [boost::optional](https://www.boost.org/doc/libs/1_65_1/libs/optional/doc/html/index.html) available.
64,924,830
Is it possible to write an API with Python so you can connect a physical ON and OFF switch via USB to a PC and when user presses the switch to ON or OFF, the python program detects it and send a signal to a web app and shows ON or OFF message on the website? I am sorry if what I am asking its not clear enough!
2020/11/20
[ "https://Stackoverflow.com/questions/64924830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12487489/" ]
I lack reputation points to comment on @Kostas To be compatible with C++14 you can try experimental namespace which has optional (if it is available/works on your compiler) ``` #include <experimental/optional> ``` then you can use ``` String(std::experimental::optional<int> &min_len,.....) min_len.value_or(-1) ``...
You can write your own class that can contain value or not if you can't use std::optional. It is not like lot of code. Can make its interface like std::optioal has or can make something different, what matters is data: ``` class OptInt { bool set_; int value_; public: OptInt() : set_(false) , value_(0) {} ...
8,210,344
I get the following error ImportError: No module named numeric if I have the following import ``` from numeric import * ``` in my python source code. How do I get this running on my Windows box against a python 2.7.x compiler?
2011/11/21
[ "https://Stackoverflow.com/questions/8210344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1004443/" ]
You will probably need to install this module: <http://numpy.scipy.org/> There are binaries for windows too, so installation should be easy. Josh
There is no common module called `numeric`. Are you sure you don't mean `import numpy`?
8,210,344
I get the following error ImportError: No module named numeric if I have the following import ``` from numeric import * ``` in my python source code. How do I get this running on my Windows box against a python 2.7.x compiler?
2011/11/21
[ "https://Stackoverflow.com/questions/8210344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1004443/" ]
There *is* a module called numeric, but it's been deprecated for years in favour of numpy. You probably want to update your code to use numpy instead. If you really need numeric, you can get it [here](http://sourceforge.net/projects/numpy/files/Old%20Numeric/24.2/), but you'll have to compile it from source for Python...
There is no common module called `numeric`. Are you sure you don't mean `import numpy`?
4,227,503
I would like to establish a good naming scheme for physical/mathematical quantities used in my simulation code. Consider the following example: ``` from math import * class GaussianBeamIntensity(object): """ Optical intensity profile of a Gaussian laser beam. """ def __init__(self, intensity_at_waist...
2010/11/19
[ "https://Stackoverflow.com/questions/4227503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/335609/" ]
I think you've already found the good balance. Expressive names are important, so I totally agree with the use of *wavelenght* instead of lambda as a class attribute. This way the interface remains clear and expressive. In a long formula, though, lambda\_ is good choice as shorthand notation, because this is a commonl...
Use Python3 and you can use the actual symbol λ for a variable name. I look forward to writing code like: ``` from math import pi as π sphere_volume = lambda r : 4/3 * π * r**3 ```
53,545,656
I know there are many post related to dictionary operations but I could not find the solution for my special case. I have list of dictinoary (repeated dictionary keys with similar or different values) and I have to create a new dictionary from this list. Eg: ``` a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': ...
2018/11/29
[ "https://Stackoverflow.com/questions/53545656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2565385/" ]
You can sort the list `a` so that the like keys are groups and the largest values are last. Then add the values so that last value is the value left in the dict: ``` >>> a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': 1}, {u'c': 1}, {u'c': 1}] >>> {k:v for k,v in (x.items()[0] for x in sorted(a))} {u'a': 2, u'...
You could do: ``` a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': 1}, {u'c': 1}, {u'c': 1}] result = {} for di in a: for key, value in di.items(): result[key] = max(value, result.get(key, value)) print(result) ``` **Output** ``` {'a': 2, 'c': 1, 'b': 2} ```
53,545,656
I know there are many post related to dictionary operations but I could not find the solution for my special case. I have list of dictinoary (repeated dictionary keys with similar or different values) and I have to create a new dictionary from this list. Eg: ``` a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': ...
2018/11/29
[ "https://Stackoverflow.com/questions/53545656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2565385/" ]
You can sort the list `a` so that the like keys are groups and the largest values are last. Then add the values so that last value is the value left in the dict: ``` >>> a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': 1}, {u'c': 1}, {u'c': 1}] >>> {k:v for k,v in (x.items()[0] for x in sorted(a))} {u'a': 2, u'...
You could use a `defaultdict`: ``` from collections import defaultdict d = defaultdict(lambda: 0) for val in a: if d[val.keys()[0]] < val.values()[0]: d[val.keys()[0]] = val.values()[0] ``` **Output** ``` {u'a': 2, u'b': 2, u'c': 1} ```
53,545,656
I know there are many post related to dictionary operations but I could not find the solution for my special case. I have list of dictinoary (repeated dictionary keys with similar or different values) and I have to create a new dictionary from this list. Eg: ``` a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': ...
2018/11/29
[ "https://Stackoverflow.com/questions/53545656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2565385/" ]
You can sort the list `a` so that the like keys are groups and the largest values are last. Then add the values so that last value is the value left in the dict: ``` >>> a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': 1}, {u'c': 1}, {u'c': 1}] >>> {k:v for k,v in (x.items()[0] for x in sorted(a))} {u'a': 2, u'...
You could do by iterating over all of your dicts and updating final dict `new_a` with its content if given key isn't in new dict or its value is lower than original value. ``` a = [{u'a': 1}, {u'a': 2}, {u'a': 1}, {u'b': 2}, {u'b': 1}, {u'c': 1}, {u'c': 1}] new_a = {} for dict_ in a: key, value = list(dict_.items...
67,268,013
I have been trying to draw a networkx multidigraph with multiple self-loops on nodes using matplotlib for quite a few days now but nothing works. After multiple tests, I narrowed the problem to Networkx with Matplotlib. I executed the following tutorial <https://networkx.org/documentation/latest/auto_examples/drawing/p...
2021/04/26
[ "https://Stackoverflow.com/questions/67268013", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6099112/" ]
any time GoogleFinance() reutrns a historical array, you need to INDEX() it to get just the single answer. It's almost always the second row and second column of the array that you want. So: ``` =INDEX(Goooglefinance(.... ), 2, 2) ```
I've tested your function and the error ***Function MULTIPLY parameter 2 expects number values. But 'Date' is a text and cannot be coerced to a number*** is due to this part `E2*GOOGLEFINANCE("Currency:"&F2&$G$1,"price", H2)` in your IFS function. The return value of the `GOOGLEFINANCE("Currency:"&F2&$G$1,"price", H2)...
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
you use `.` instead of `->` because of this declaration of parameters: `int ball_room(ball *b, int i, int n)` `b` is expected to be pointer to data with type `ball`, so you can access it in various ways: 1. array way: e.g. `b[5].somefield = 15` - you use dot here, because if `b` is of type `ball *`, it means that `...
In C/C++ an array devolves into the address of it's first member. So when you pass the array to `ball_room` what actually gets passed is `&ball[0]`. Now inside `ball_room` the reverse happens. `b` is a pointer to ball. But here you use it as an array `b[j]`. So it un-devolves back into an array of structs. So what `b[...
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
Given `ball *b`, `b[j]` is an element from the elements that `b` points to. Thus `b[j]` is not a pointer; it is a struct. Since it is a struct, you use `.` to refer to members in it. The definition of `b[j]` in the C standard is that it is `*((b)+(j))`. So it takes the pointer `b`, moves `j` elements beyond it, and th...
you use `.` instead of `->` because of this declaration of parameters: `int ball_room(ball *b, int i, int n)` `b` is expected to be pointer to data with type `ball`, so you can access it in various ways: 1. array way: e.g. `b[5].somefield = 15` - you use dot here, because if `b` is of type `ball *`, it means that `...
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
you use `.` instead of `->` because of this declaration of parameters: `int ball_room(ball *b, int i, int n)` `b` is expected to be pointer to data with type `ball`, so you can access it in various ways: 1. array way: e.g. `b[5].somefield = 15` - you use dot here, because if `b` is of type `ball *`, it means that `...
In C, the array name is a pointer to array’s first element, hence your function declaration has name `ball *b`and works when you pass a `ball[]` instance. Try dynamically allocating the memory by using `malloc()` and passing that pointer to your function.
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
you use `.` instead of `->` because of this declaration of parameters: `int ball_room(ball *b, int i, int n)` `b` is expected to be pointer to data with type `ball`, so you can access it in various ways: 1. array way: e.g. `b[5].somefield = 15` - you use dot here, because if `b` is of type `ball *`, it means that `...
For explanation of the current issue, see [Eric](https://stackoverflow.com/users/298225/eric-postpischil)'s [answer](https://stackoverflow.com/a/51264543/1312382); in some of the answers given so far there is dangerous wording applied, so just to make clear: When do we have an array and when a pointer??? Consider the ...
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
Given `ball *b`, `b[j]` is an element from the elements that `b` points to. Thus `b[j]` is not a pointer; it is a struct. Since it is a struct, you use `.` to refer to members in it. The definition of `b[j]` in the C standard is that it is `*((b)+(j))`. So it takes the pointer `b`, moves `j` elements beyond it, and th...
In C/C++ an array devolves into the address of it's first member. So when you pass the array to `ball_room` what actually gets passed is `&ball[0]`. Now inside `ball_room` the reverse happens. `b` is a pointer to ball. But here you use it as an array `b[j]`. So it un-devolves back into an array of structs. So what `b[...
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
In C/C++ an array devolves into the address of it's first member. So when you pass the array to `ball_room` what actually gets passed is `&ball[0]`. Now inside `ball_room` the reverse happens. `b` is a pointer to ball. But here you use it as an array `b[j]`. So it un-devolves back into an array of structs. So what `b[...
In C, the array name is a pointer to array’s first element, hence your function declaration has name `ball *b`and works when you pass a `ball[]` instance. Try dynamically allocating the memory by using `malloc()` and passing that pointer to your function.
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
Given `ball *b`, `b[j]` is an element from the elements that `b` points to. Thus `b[j]` is not a pointer; it is a struct. Since it is a struct, you use `.` to refer to members in it. The definition of `b[j]` in the C standard is that it is `*((b)+(j))`. So it takes the pointer `b`, moves `j` elements beyond it, and th...
In C, the array name is a pointer to array’s first element, hence your function declaration has name `ball *b`and works when you pass a `ball[]` instance. Try dynamically allocating the memory by using `malloc()` and passing that pointer to your function.
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
Given `ball *b`, `b[j]` is an element from the elements that `b` points to. Thus `b[j]` is not a pointer; it is a struct. Since it is a struct, you use `.` to refer to members in it. The definition of `b[j]` in the C standard is that it is `*((b)+(j))`. So it takes the pointer `b`, moves `j` elements beyond it, and th...
For explanation of the current issue, see [Eric](https://stackoverflow.com/users/298225/eric-postpischil)'s [answer](https://stackoverflow.com/a/51264543/1312382); in some of the answers given so far there is dangerous wording applied, so just to make clear: When do we have an array and when a pointer??? Consider the ...
51,263,370
I am trying to implement k-nearest neighbor algorithm with the dataset which I have preprocessed. I imported the data as pandas dataframe and then converted it into numpy array but the following error is occuring- ``` File "/home/user/Documents/Mooc_implementation.py", line 8, in <module> x = num_data[:,:10] F...
2018/07/10
[ "https://Stackoverflow.com/questions/51263370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9355642/" ]
For explanation of the current issue, see [Eric](https://stackoverflow.com/users/298225/eric-postpischil)'s [answer](https://stackoverflow.com/a/51264543/1312382); in some of the answers given so far there is dangerous wording applied, so just to make clear: When do we have an array and when a pointer??? Consider the ...
In C, the array name is a pointer to array’s first element, hence your function declaration has name `ball *b`and works when you pass a `ball[]` instance. Try dynamically allocating the memory by using `malloc()` and passing that pointer to your function.
58,411,930
After all of web searching and coming up of no answer to this, I thought of asking this question on this platform. I had an application container which i try to connect with mine database container but due to reasons unaware mine application is not able to connect. I am providing all the relevant information required f...
2019/10/16
[ "https://Stackoverflow.com/questions/58411930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5182512/" ]
in my case i changed ``` mysql://root:root@localhost:3307/db ``` to ``` mysql://root:root@Gateway ip:3307/test_db ``` the Gateway ip you can find it in ``` docker network ls docker network inspect ```
Change 'HOST': 'db' to 'HOST': '**localhost**' in settings.py file. Because you map the default MySQL port from container to MySQL default port in your main host.
29,678,324
I'm just learning python so be gentle. I want to read a file and that to be one function and then have another function work on what the previous function "read". I am having trouble passing the result on one function to another. Here is what I have no far: I want to call read\_file more than once and to be able to pa...
2015/04/16
[ "https://Stackoverflow.com/questions/29678324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4797120/" ]
Here is your modified code (comments in uppercase for easier finding, not rudeness): ``` def read_file(): user_input = raw_input("please put date needed in x.xx form: ") path = r'C:\\Users\\CP\\documents\\' + user_input allFiles = glob.glob(path + '/*.csv') frame = pd.DataFrame() list = [] for ...
If you are trying to pass frame from one function to the other, you need to declare it outside the scope of the function. Otherwise we need more information about what you are trying to accomplish. ``` frame = None def read_file(): user_input = raw_input("please put date needed in x.xx form: ") path = r'C:\\Us...
51,171,741
I am using Python for the first time to create a simple JSON parser. However, when printing the JSON data to the console, it includes many extra brackets and other symbols that are unwanted. I am also running Python 2.7.10. ``` import json from urllib2 import urlopen response = urlopen("https://finance.yahoo.com/webs...
2018/07/04
[ "https://Stackoverflow.com/questions/51171741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6131554/" ]
I think you are actually printing a tuple with python 2 `print` syntax and the `u` character is a unicode flag ([What exactly do "u" and "r" string flags do, and what are raw string literals?](https://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-and-what-are-raw-string-literals)). Also i...
Convert name and price to string `print(str(name), str(price))` or use `name = str(item['resource']['fields']['name'])`
70,423,743
I'm new in python and programming in general. I have this project to create a simple library to add new authors and upload books. I must also display the uploaded book details(total words, most common words, different words, etc.) when I open the book. Now to do this I know that I first must open the uploaded book in r...
2021/12/20
[ "https://Stackoverflow.com/questions/70423743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17725025/" ]
``` <v-btn class="mr-4" :loading="saveLoading == index" @click="submit(item, index)" > data: () => ({ valid: true, saveLoading: -1, }) submit (formItem, index) { this.saveLoading = index console.log(formItem) // POST the formItem and make the saveLoading false in async then(),...
If you are generating the forms from the api response, mean that in some way you are attaching the response to the Vue Data property. If so, you could easily enrich the objects of the array (the forms object) to have a isLoading property. So the result will be something like: ``` API RESPONSE [ { form_name: ...
70,423,743
I'm new in python and programming in general. I have this project to create a simple library to add new authors and upload books. I must also display the uploaded book details(total words, most common words, different words, etc.) when I open the book. Now to do this I know that I first must open the uploaded book in r...
2021/12/20
[ "https://Stackoverflow.com/questions/70423743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17725025/" ]
The problem is that you have only one variable. You could do `saveLoading1` to `saveLoadingN` but that's not very useful. ```js var forms = [ { form_name: 'Form One', name: 'Peter', email: '[email protected]' }, { form_name: 'Form Two', name: 'John', email: '[email protected]...
If you are generating the forms from the api response, mean that in some way you are attaching the response to the Vue Data property. If so, you could easily enrich the objects of the array (the forms object) to have a isLoading property. So the result will be something like: ``` API RESPONSE [ { form_name: ...
37,143,664
Just trying to pull some lat/lon info from EXIF data on a bunch of photos, but code is throwing a `KeyError` even though that key is used (successfully) later on to print specific coordinates. Dictionary in question is "`tags`" - `'GPS GPSLatitude'` and `'GPS GPSLongitude'` are both keys in `tags.keys()`; I've triple...
2016/05/10
[ "https://Stackoverflow.com/questions/37143664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5957741/" ]
`GPS GPSLatitude` and `GPS GPSLongitude` may not be present in all tag dicts. Instead of accessing keys as `tags['GPS GPSLatitude']` & `tags['GPS GPSLongitude']` , you can also access these as `tags.get('GPS GPSLatitude')` & `tags.get('GPS GPSLongitude')` This wil return `None` instead of throwing error, where you can...
I think @BryanOakley has the right idea. If the key isn't in the dict, it isn't there. (Those fields are optional, and some files might not have the data.) So you can use the `dict.get(key, default=None)` approach, and replace the Key Error with a default value. ``` jpegs = [file for file in os.listdir(path) if file.e...
58,673,628
I have been leaning python and programming for not so long. So you may find my question silly. I am reviewing generator and try to generate 'yes', 'no' infinitely just to understand the concept. I have tried this code but having "yes" each time ``` def yes_or_no(): answer = ["yes","no"] i=0 while True: ...
2019/11/02
[ "https://Stackoverflow.com/questions/58673628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12308317/" ]
`yes_no()` produces the generator; you want to call `next` on the same generator each time, rather than printing the same first element over and over. ``` c = yes_no() print(next(c)) print(next(c)) # etc. ``` That said, there's no need for a separate counter; just yield `yes`, then yield `no`, then repeat. ``` def...
You need to initialize the generator and then call `next` on the initialized generator object: ``` c = yes_or_no() ``` Now you need to call `next` on `c`: ``` print(next(c)) print(next(c)) ``` --- In your current code `c=next(yes_or_no())`: * `yes_or_no()` will initialize the generator and calling `next` on it ...
58,673,628
I have been leaning python and programming for not so long. So you may find my question silly. I am reviewing generator and try to generate 'yes', 'no' infinitely just to understand the concept. I have tried this code but having "yes" each time ``` def yes_or_no(): answer = ["yes","no"] i=0 while True: ...
2019/11/02
[ "https://Stackoverflow.com/questions/58673628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12308317/" ]
`yes_no()` produces the generator; you want to call `next` on the same generator each time, rather than printing the same first element over and over. ``` c = yes_no() print(next(c)) print(next(c)) # etc. ``` That said, there's no need for a separate counter; just yield `yes`, then yield `no`, then repeat. ``` def...
While your function does return a generator and it has been stated by others that all you need to do is iterate over it using a loop or calling next in succession. Python provides you a great library called `itertools` to do exactly this thing; it's called [`itertools.cycle`](https://docs.python.org/3/library/itertools...
19,351,065
I'm trying to get a deeper understanding of how Python works, and I've been looking at the grammar shown at <http://docs.python.org/3.3/reference/grammar.html>. I notice it says you would have to change parsermodule.c also, but truthfully I'm just not following what's going on here. I understand that a grammar is a s...
2013/10/13
[ "https://Stackoverflow.com/questions/19351065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1029146/" ]
That is basically an [EBNF](http://en.wikipedia.org/wiki/EBNF) (Extended Backus–Naur Form) specification.
When you write a program in a language, the very first thing your interpreter/compiler must do in order to go from a sequence of characters to actual action is to translate that sequence of characters in a higher complexity structure. To do so, first it chunks up your program in a sequence of tokens expressing what eac...
19,351,065
I'm trying to get a deeper understanding of how Python works, and I've been looking at the grammar shown at <http://docs.python.org/3.3/reference/grammar.html>. I notice it says you would have to change parsermodule.c also, but truthfully I'm just not following what's going on here. I understand that a grammar is a s...
2013/10/13
[ "https://Stackoverflow.com/questions/19351065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1029146/" ]
A grammar is used to describe all possible strings in a language. It is also useful in specifying how a parser should parse the language. In this grammar it seems like they are using their own version of [EBNF](http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form), where a non-terminal is any lowercase word ...
That is basically an [EBNF](http://en.wikipedia.org/wiki/EBNF) (Extended Backus–Naur Form) specification.
19,351,065
I'm trying to get a deeper understanding of how Python works, and I've been looking at the grammar shown at <http://docs.python.org/3.3/reference/grammar.html>. I notice it says you would have to change parsermodule.c also, but truthfully I'm just not following what's going on here. I understand that a grammar is a s...
2013/10/13
[ "https://Stackoverflow.com/questions/19351065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1029146/" ]
The python grammar - as most others - is given in [BNF](http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form) or **Backus–Naur Form**. Try reading up on how to read it but the basic structure is: ``` <something> ::= (<something defined elsewhere> | [some fixed things]) [...] ``` This is read as a `<something>` **is...
When you write a program in a language, the very first thing your interpreter/compiler must do in order to go from a sequence of characters to actual action is to translate that sequence of characters in a higher complexity structure. To do so, first it chunks up your program in a sequence of tokens expressing what eac...
19,351,065
I'm trying to get a deeper understanding of how Python works, and I've been looking at the grammar shown at <http://docs.python.org/3.3/reference/grammar.html>. I notice it says you would have to change parsermodule.c also, but truthfully I'm just not following what's going on here. I understand that a grammar is a s...
2013/10/13
[ "https://Stackoverflow.com/questions/19351065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1029146/" ]
A grammar is used to describe all possible strings in a language. It is also useful in specifying how a parser should parse the language. In this grammar it seems like they are using their own version of [EBNF](http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form), where a non-terminal is any lowercase word ...
The python grammar - as most others - is given in [BNF](http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form) or **Backus–Naur Form**. Try reading up on how to read it but the basic structure is: ``` <something> ::= (<something defined elsewhere> | [some fixed things]) [...] ``` This is read as a `<something>` **is...
19,351,065
I'm trying to get a deeper understanding of how Python works, and I've been looking at the grammar shown at <http://docs.python.org/3.3/reference/grammar.html>. I notice it says you would have to change parsermodule.c also, but truthfully I'm just not following what's going on here. I understand that a grammar is a s...
2013/10/13
[ "https://Stackoverflow.com/questions/19351065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1029146/" ]
A grammar is used to describe all possible strings in a language. It is also useful in specifying how a parser should parse the language. In this grammar it seems like they are using their own version of [EBNF](http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form), where a non-terminal is any lowercase word ...
When you write a program in a language, the very first thing your interpreter/compiler must do in order to go from a sequence of characters to actual action is to translate that sequence of characters in a higher complexity structure. To do so, first it chunks up your program in a sequence of tokens expressing what eac...
53,515,926
I have data stored in a parquet files and hive table partitioned by year, month, day. Thus, each parquet file is stored in `/table_name/year/month/day/` folder. I want to read in data for only some of the partitions. I have list of paths to individual partitions as follows: ```py paths_to_files = ['hdfs://data/table_...
2018/11/28
[ "https://Stackoverflow.com/questions/53515926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7064628/" ]
Reading the direct file paths to the parent directory of the year partitions should be enough for a dataframe to determine there's partitions under it. However, it wouldn't know what to name the partitions without the directory structure `/year=2018/month=10`, for example. Therefore, if you have Hive, then going via ...
Your data isn't stored in a way optimal for parquet so you'd have to load files one by one and add the dates Alternatively, you can move the files to a directory structure fit for parquet ( e.g. .../table/year=2018/month=10/day=29/file.parquet) then you can read the parent directory (table) and filter on year, month, ...
12,568,689
I am new to python (2nd) day and working on a problem that asks me to Write a program that reads ASCII files (asks for file name as input), checks if it has more than two words and prints out the two first words of the file on screen. Its a little vague but I am going to assume the file is all str, deliminiated by sp...
2012/09/24
[ "https://Stackoverflow.com/questions/12568689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1690243/" ]
That code should be written as: ``` if len(words) > 2: print 'There are more than two words' firsttow = words[:2] print firstrow elif len(words) <2: print 'There are under 2 words, no words will be shown' ``` Note the indentation, and the use of `elif` (which means "else if").
``` with codecs.open(name, encoding='utf-8') as f: words=[] #define words here for line in f: line = line.lstrip(BOM) words.extend(line.split()) #append words from each line to words if len(words) > 2: print 'There are more than two words' firsttow = words[:2] ...
5,093,153
I'm wondering how to go about implementing a macro recorder for a python gui (probably PyQt, but ideally agnostic). Something much like in Excel but instead of getting VB macros, it would create python code. Previously I made something for Tkinter where all callbacks pass through a single class that logged actions. Unf...
2011/02/23
[ "https://Stackoverflow.com/questions/5093153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/98967/" ]
Thinking in high level, this is what I'd do: Develop a decorator function, with which I'd decorate every event-handling functions. This decorator functions would take note of thee function called, and its parameters (and possibly returning values) in a unified data-structure - taking care, on this data structure, to ...
An example of what you're looking for is in [mayavi2](http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/application.html#automatic-script-generation). For your purposes, mayavi2's "script record" functionality will generate a Python script that can then be trivially modified for other cases. I hear...
5,093,153
I'm wondering how to go about implementing a macro recorder for a python gui (probably PyQt, but ideally agnostic). Something much like in Excel but instead of getting VB macros, it would create python code. Previously I made something for Tkinter where all callbacks pass through a single class that logged actions. Unf...
2011/02/23
[ "https://Stackoverflow.com/questions/5093153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/98967/" ]
You could apply the command design pattern: when your user executes an action, generate a command that represents the changes required. You then implement some sort of command pipeline that executes the commands themselves, most likely just calling the methods you already have. Once the commands are executed, you can s...
An example of what you're looking for is in [mayavi2](http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/application.html#automatic-script-generation). For your purposes, mayavi2's "script record" functionality will generate a Python script that can then be trivially modified for other cases. I hear...
2,032,706
i have been trying to running some pinax code inside pydev eclipse i keep on having this error Error: Can't import Pinax. Make sure you are in a virtual environment that has Pinax installed or create one with pinax-boot.py. my question is how do i run pinax inside eclipse using django built in server i am python n...
2010/01/09
[ "https://Stackoverflow.com/questions/2032706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/81850/" ]
How about ``` map.connect ':user/:repo/commit/:sha', :action => :index ``` Or use `map.resource` instead of `map.connect` if you need a RESTful route. In the controller, the URL information can be retrieved from params, for example `params[:user]` returns the username.
You can name your routes as you like, and specify which controllers and actions you'd like to use them with. For example, you might have: ``` map.connect ':user/:repo/commit/:sha', :controller => 'transactions', :action => 'commit' ``` This would send the request to the 'commit' method in 'transactions' controller....
2,032,706
i have been trying to running some pinax code inside pydev eclipse i keep on having this error Error: Can't import Pinax. Make sure you are in a virtual environment that has Pinax installed or create one with pinax-boot.py. my question is how do i run pinax inside eclipse using django built in server i am python n...
2010/01/09
[ "https://Stackoverflow.com/questions/2032706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/81850/" ]
If commit is a RESTful controller that uses :sha instead of an id to find records. You could do this instead: ``` map.resource :commits, :path_prefix => ':user/:repo', :as => 'commit' ``` It will create the standard RESTful routes that look like `http://yoursite.tld/:user/:repo/commit/:id` Again, if you'll never be...
How about ``` map.connect ':user/:repo/commit/:sha', :action => :index ``` Or use `map.resource` instead of `map.connect` if you need a RESTful route. In the controller, the URL information can be retrieved from params, for example `params[:user]` returns the username.
2,032,706
i have been trying to running some pinax code inside pydev eclipse i keep on having this error Error: Can't import Pinax. Make sure you are in a virtual environment that has Pinax installed or create one with pinax-boot.py. my question is how do i run pinax inside eclipse using django built in server i am python n...
2010/01/09
[ "https://Stackoverflow.com/questions/2032706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/81850/" ]
If commit is a RESTful controller that uses :sha instead of an id to find records. You could do this instead: ``` map.resource :commits, :path_prefix => ':user/:repo', :as => 'commit' ``` It will create the standard RESTful routes that look like `http://yoursite.tld/:user/:repo/commit/:id` Again, if you'll never be...
You can name your routes as you like, and specify which controllers and actions you'd like to use them with. For example, you might have: ``` map.connect ':user/:repo/commit/:sha', :controller => 'transactions', :action => 'commit' ``` This would send the request to the 'commit' method in 'transactions' controller....
7,321,113
I'm using Cairo/RSVG based solution for rasterizing SVG to PNG. It's already beeb described on StackOverflow in [Convert SVG to PNG in Python](https://stackoverflow.com/questions/6589358/convert-svg-to-png-in-python). However, this solution doesn't seem to work with custom fonts. I've found [this page describing embe...
2011/09/06
[ "https://Stackoverflow.com/questions/7321113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/60711/" ]
I have spent a week researching this very issue and concluded that the best way to handle server-side rendering/rasterizing of SVG with custom fonts is to install those fonts on the server. The tools I tried (rsvg, imagemagick, phantomjs, qtwebkit...) could not handle web fonts and svg fonts. Google has [several hundr...
You can try to use [inkscape](http://www.inkscape.org), perhaps this gives you better results: ``` inkscape inputfile.svg --export-png=exportfile.png ``` Running this from python is described here: [Calling an external command in Python](https://stackoverflow.com/questions/89228/how-to-call-external-command-in-pyth...
7,321,113
I'm using Cairo/RSVG based solution for rasterizing SVG to PNG. It's already beeb described on StackOverflow in [Convert SVG to PNG in Python](https://stackoverflow.com/questions/6589358/convert-svg-to-png-in-python). However, this solution doesn't seem to work with custom fonts. I've found [this page describing embe...
2011/09/06
[ "https://Stackoverflow.com/questions/7321113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/60711/" ]
I have spent a week researching this very issue and concluded that the best way to handle server-side rendering/rasterizing of SVG with custom fonts is to install those fonts on the server. The tools I tried (rsvg, imagemagick, phantomjs, qtwebkit...) could not handle web fonts and svg fonts. Google has [several hundr...
With Imagemagick I still struggle with svg rasterizing with fonts that are installed on the server and can be used in certain operations, but fail when using -convert from .svg to .png.... It seems to turn every type of text into arial. I think it may be a bug with ImageMagick or a certain format needed in the .svg
7,321,113
I'm using Cairo/RSVG based solution for rasterizing SVG to PNG. It's already beeb described on StackOverflow in [Convert SVG to PNG in Python](https://stackoverflow.com/questions/6589358/convert-svg-to-png-in-python). However, this solution doesn't seem to work with custom fonts. I've found [this page describing embe...
2011/09/06
[ "https://Stackoverflow.com/questions/7321113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/60711/" ]
I have spent a week researching this very issue and concluded that the best way to handle server-side rendering/rasterizing of SVG with custom fonts is to install those fonts on the server. The tools I tried (rsvg, imagemagick, phantomjs, qtwebkit...) could not handle web fonts and svg fonts. Google has [several hundr...
A couple of things to check with RSVG: * That the font source files are in your system or user font path * That font names in the SVG are not quoted, even if they contain spaces. librsvg will assume the quotes are part of the font name and it won't find the source files.
66,977,521
I want to run arbitrary "code" in an argument like an anonymous function in Python. How to do this in one single line? Lambdas seems that does not work since they only take one expression. ``` def call_func(callback): callback() def f(): pkg_set_status(package_name, status) print('ok') call_func(f) ``` ...
2021/04/06
[ "https://Stackoverflow.com/questions/66977521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3274630/" ]
The structure defined by myList with the `<ol>` elements is never actually added to the document. If you concatenate the `<ol>`, then the `<li>` entries, then `</ol>` all to wrapper.innerHTML then it should work. For example something like... ``` var myList = "<ol>"; for (var i = 0; i < properties.length; i++) { ...
If you would check your structure in dev tools you would see there was no `ol` element in finale result. So you can create it: ``` var myList = document.createElement("ol"); ``` Then fill it with `li`: ``` myList.innerHTML ``` And then insert it: ``` idk.insertAdjacentElement("afterbegin", myList); ``` ```j...