ipython

Ignore IPython magic in python

天涯浪子 提交于 2019-12-11 08:46:35
问题 What is the best way to ignore IPython magic when running scripts using the python interpreter? I often include IPython magic in my script files because it work with the code interactively. For example, with the autoreload magic, I don't have to keep reload -ing the modules after I make some changes and fix bugs: %load_ext autoreload %autoreload 2 However, when I try to run this script using a usual python interpreter, I get an error: File "<string>", line 1 %load_ext autoreload ^ SyntaxError

Fix precision issues when *displaying* floats in python

穿精又带淫゛_ 提交于 2019-12-11 07:03:17
问题 I'm reading out a text file with some float numbers using np.loadtxt . This is what my numpy array looks like: x = np.loadtxt(t2) print(x) array([[ 1.00000000e+00, 6.61560000e-13], [ 2.00000000e+00, 3.05350000e-13], [ 3.00000000e+00, 6.22240000e-13], [ 4.00000000e+00, 3.08850000e-13], [ 5.00000000e+00, 1.11170000e-10], [ 6.00000000e+00, 3.82440000e-11], [ 7.00000000e+00, 5.39160000e-11], [ 8.00000000e+00, 1.75910000e-11], [ 9.00000000e+00, 2.27330000e-10]]) I separate out the first column

IPython Language Kernel Implementation in Erlang

孤者浪人 提交于 2019-12-11 06:55:48
问题 I'm currently building an Erlang language kernel backend for IPython, and I'm testing it out in the console. What I have working: Start ipython console and the erlang kernel Erlang kernel reads contents of kernel.json file which contains all the port numbers for zmq Create zmq bindings for the shell , heartbeat , control , iopub sockets using the erlzmq2 library. Created functions to parse messages from IPython Create a process for the heartbeat server to run on and return messages to IPython

Processing results from asyncmap as they come in

≯℡__Kan透↙ 提交于 2019-12-11 06:52:17
问题 I am trying to process data in parallel using ipython's parallel processing. I am following the instructions by @minrk in answer to the question on how to get intermidiate results in ipython parallel processing?. Since the data is heterogeneous some of the processing tasks are finished sooner than others and I would like to save them as soon as they become available. I do this in the following fashion: from IPython.parallel import Client def specialfunc(param): import time if param > 8: raise

Webcam can not show picture with OpenCV in python 3.7

大憨熊 提交于 2019-12-11 06:47:36
问题 I use the following code copied from opencv website : import cv2 cap = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = cap.read() cv2.imshow('frame',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() But the image is black with some white noise : I am pretty sure the problems is not come from my webcam device because I use "camera" APP in Windows 10, the picture can display well. The following is my python environment : Python : 3.7

Is there a way to make Python's console display docstrings nicely?

好久不见. 提交于 2019-12-11 06:39:48
问题 Whenever I use iPython to ask for a docstring in the PyCharm console, it gives me something that looks like . Is there an easy way to make it return beautiful, word-wrapped docstrings? 来源: https://stackoverflow.com/questions/44937959/is-there-a-way-to-make-pythons-console-display-docstrings-nicely

Capturing library f2py call stdout from ipython

青春壹個敷衍的年華 提交于 2019-12-11 05:58:17
问题 I'm using Jupyter notebook with a Python 3 kernel. If I run: import scipy.optimize scipy.optimize.minimize( lambda _: 1, 0, method='COBYLA', options={'iprint': 1, 'disp': True, 'maxiter': 2}) I expect to get diagnostic optimization info printed to the ipython notebook. However, this prints to console. I suspect this is the case because the optimization routine is implemented in Fortran, and is interfaced in scipy through f2py. The COBYLA Fortran file does the actual printing. How can I pipe

Issues with using timeit in ipython

自古美人都是妖i 提交于 2019-12-11 05:27:53
问题 I was quickly trying to time 2 functions in ipython, m1() and m2() doing the same task with 2 different implementation. In [23]: %timeit for x in range(100): m1(a) 10000 loops, best of 3: 57.6 us per loop In [24]: %timeit for x in range(100): m2(a) 10000 loops, best of 3: 108 us per loop Result: the first implementation is almost 2x faster. So far, so good. Out of curiousity, I changed the range of the for loop above, and now I am at a loss making sense of the output. In [25]: %timeit for x

How to impute values in a column when certain conditions are fulfilled in other columns using fillna()

强颜欢笑 提交于 2019-12-11 05:09:45
问题 I've calculated the counts when credit_history has NaN values. Output when Credit_History is NaN: Self_Employed Yes 532 No 32 Married No 398 Yes 21 And for the numerical values, I calculated the mean for all columns output for non-numerical values when Credit_History is NaN: Mean Applicant Income: 54003.1232 LoanAmount: 35435.12 Loan_Amount_Term: 360 ApplicantIncome: 30000 How do I now use fillna() in these cases: Case 1: When Self_Employed = Y and Married = N; Credit_History should be 0 Case

How to use jupyter_client to get the execute result?

北城以北 提交于 2019-12-11 04:47:31
问题 I'd like to use jupyter_client to execute some python code and get result. Here's my sample code. But I could not get the output hello world , Could anyone help me ? Thanks import jupyter_client kernel_manager, kernel_client = jupyter_client.manager.start_new_kernel(kernel_name='python3') kernel_client.execute("print('hello world')") kernel_client.get_shell_msg() 回答1: The output wont be on the standard output, it will be in a result object. Check this snippet: https://www.snip2code.com