Python Definition and 661 Threads

PYTHON was a Cold War contingency plan of the British Government for the continuity of government in the event of nuclear war.

View More On Wikipedia.org
  1. N

    Python How to combine integration equation in Python?

    I'm calculating key rate (R^Rate-wise) by integrating R(eta) over all possible eta from 0 to 1, with a probability distribution (PDTC) which is a log-normal distribution. The equation of log-normal distribution: The equation of R(eta): Therefore, R^Rate-wise =...
  2. R

    Example illustraing Quantum programming

    I'm interested in quantum programming. So far I've managed to use Java and Python inside Datamelt computation project for physics simulations and for various statistical plots. Now I want to make a simple code that illustates quantum computing, and maybe even to visualize its principles (for...
  3. Avatrin

    Python Showing rotational trajectory with Python

    Hi I have a list of 3D angular velocities (a numerical solution to an ODE). I want to show the trajectory this rotation would cause by mapping it out on the unit sphere. How can I go about doing that? What is the best way to approach this?
  4. Danny Boy

    Animation using matplotlib query

    I am trying to animate a plot of two distinct points (blue and green points) moving about the complex unit circle using Python's Matplotlib library. The problem I am having is that the animation does not remove and update the previous data points but rather sequentially smears it on the unit...
  5. m4r35n357

    Python Damped & Driven Pendulums (in _pure_ Python)

    This is another application of using Taylor recurrences (open access) to solve ODEs to arbitrarily high order (e.g. 10th order in the example invocation). It illustrates use of trigonometric recurrences, rather than the product recurrences in my earlier Lorenz ODE posts. Enjoy! #!/usr/bin/env...
  6. W

    Python Using Different Versions of Python - Compatibility/Dependencies?

    Hi All, I am trying to learn versions 2,3 of Python ( long story). Just curious as to the "Dependency/Compatibility" issues between and within versions 2 and 3. Are packages/libraries in 3.x available for 3.x' where x'>x ? How about for version 2? Specifically, at this point, I am trying to...
  7. starstruck_

    Python What downloads are required to work with Python?

    Hey everyone! This might be a bit of a dumb question, but I'm not familiar with much in the programming world. I know a few languages that I've learned on my own (online) or through a course in school (MATLAB). When it comes down to coding outside of MATLAB or a website, I'm not sure where to...
  8. W

    Python De-Shebanging a Python program file

    Hi all, I had shebanged a Python program file to train myself to run Python from the command line or search box. Problem is now I cannot access my old text-based .py files. Every time I click on them to open, they run in the command line. How can I access the text format again?
  9. JD_PM

    Python How to plot vector fields in Matplotlib

    Hi, I want to plot the vector field ##\vec F = ye^x \hat i + (x^2 + e^x) \hat j + z^2e^z \hat k## The code I have tried: # The components of the vector field F_x = y*e**x F_y = x**2 + e**x F_z = z**2*e**z# The grid xf = np.linspace(-0.15, 2.25, 8) yf = np.linspace(-0.15, 2.25, 8) zf =...
  10. C

    Python How to estimate a GARCH model in python (without standard function)?

    Hi, I want to program an GARCH model for exchange rates. To do this, I calculated the residuals. Next, I did the following (in python) def main(): vP0 = (0.1, 0.05, 0.92) a = minimize(garch_loglike, vP0, eps, bounds = ((0.0001, None), (0.0001, None), (0.0001, None))...
  11. JD_PM

    Python How to make an animation in SymPy using Python

    I want to make an animation where a (red) ball departs from (0,0) and draws the function ##f(x) = sin x## This is what I know: How to plot ##f(x) = sin x## To do so I followed instructions from the worksheet. Actually I'd have done: But I guess they want to me to it in that way because...
  12. JD_PM

    Python Plotting a Helix in Sympy: Troubleshooting and Tips

    I asked this question on SO, but I am having problems with it (I cannot even get into my account now). It seems that people using the IP I am using are asking a lot and that limits the number of questions I can ask. Please have a look at my question. Here's the link: [Moderators note: bold large...
  13. m4r35n357

    Python What is the Nelder-Mead algorithm and how can it be implemented in pure Python?

    Adapted from this code, which is an implementation of the algorithm described here. Removed dependency on Numpy Use as library code or test Himmelblau's function from copy import copy from sys import stderr, argv def replace_worst(data, new): del data[-1] data.append(new) def...
  14. caffeinemachine

    Python How to generate a tiling (in python if possible)

    I was reading this wikiperdia article on polyminos (https://en.wikipedia.org/wiki/Polyomino). The pictures look very nice. Example I want to learn how to generate these figures myself in an interactive way. Basically I want to start with a polymino and then I want to be able to translate (by...
  15. JD_PM

    Looking for a bunch of solved Sympy problems (Calculus)

    Two weeks ago I had no idea on how to code using Python. Now I have completed an online course on functions, loops and strings. However, in that course I did not practice using the specific library called Sympy. Besides, I will use Python in the Physics-Math background, for solving problems like...
  16. JD_PM

    Python Python for Vector Calculus: Books & Online Resources

    I am looking for a book for learning Python so as to compute matrices, eigenvalues, eigenvectors, divergence, curl (i.e vector calculus). If you also have online recommendations please feel free to write them.
  17. websterling

    Python What are Good Reference Books for Python?

    Back in the day, when Perl was my go to language, Programming Perl, the Camel Book, from O'Reilly was The Reference. It was the quick and concise way to get an answer. And you'd probably learn something you weren't necessarily looking for and get a chuckle along the way. Now that Python is my...
  18. K

    Python Visual Python Pendulum: Solving the Forces

    Hello and thanks in advance for your help. For about a week now, I've been trying to write what should be a simple python program. The idea is first to write a program for a simple harmonic pendulum, then adapt it to a spring pendulum. However, in order to do this, I have to write the simple...
  19. C

    Python 3d interpolation in Python using a mesh grid

    I have four arrays of data xvalues[], yvalues[], zvalues[] and wvalues[] and I want to create, from this data, an interpolated function w = f(x,y,z). Is it easy to do this in python using first a meshgrid and then calling scipy's interpolation? e.g toy set up is something like, where wvalues...
  20. Othman0111

    Python How to GOTO a certain line in Python to repeat?

    Hi everyone, I'm trying to create a sequence that evaluates r for i= 1 to 10 and 100 to 110 ...N (evaluate 10 skip 90 repeats till N). If python has a GoTo function, I would've used it to return the previous line to repeat. But I couldn't find a function like that anywhere on the internet. 1...
  21. GoldenBear

    Python Suggestions for books about scientific computing using Python

    Looking for suggestions on books (or other learning material) that will help me improve my skills using Python for scientific computing. I am comfortable with Python programming (syntax, conditional statements, loops, etc.), and use it for data analysis in my undergraduate experimental physics...
  22. Eclair_de_XII

    Python I writing a program telling time on Python

    Homework Statement "Using the time module, write a program that tells one the current time in hours, minutes, and seconds, and time since January the first of 1970." Homework Equations import time % = mod division int = returns integer value of number The Attempt at a Solution import time...
  23. A

    Python How to get output from a layer during training in Keras?

    In Keras, the method model.fit() is used to train the neural network. How can I get the output from any hidden layer during training? Consider following code where neural network is trained to add two time series #multivariate data preparation #multivariate multiple input cnn example from numpy...
  24. W

    Python Extended Comments for Python 3?

    Hi All, I am having trouble figuring out how to do extended, i.e., many-lined, comments. I know the format is ( copied from website): “””” Problem is that, while I can find the '' in my Qwerty keyboard, I can't figure out how to find the rest in my keyboard. I assume all Qwertys are the...
  25. scottdave

    Sites for some practice programming

    This is not a question, but a note, which I thought could help students. I thought I would share this here, as people may be looking for practice problems. My professor in the Python course I just finished recommended https://projecteuler.net/ as a site to practice using programming skills...
  26. W

    Python Using Python 32-bit (with Idle) in 64-bit System

    Hi, I somehow carelessly installed Python 3.72, 32-bit in my 64-bit system. Is this a workable situation or will I pay a price eventually in a conflict between 32-bit software living in a 64-bit system? Should I uninstall and reinstall a 64-bit version?
  27. Abimbola1987

    MATLAB How can attenuation be removed using SCIPY or MATLAB?

    Dear Sirs, I have a signal which has an attenuation of 20dB per decade, how do I remove this attenuation using SCIPY? Alternatively how to do it in MATLAB if there are no SCIPY users here? I'm a SCIPY/MATLAB novice fyg. Thank you for your kind assistance Abim
  28. m4r35n357

    Python More cool automatic differentiation (Hamiltonian)

    Well I think it is cool anyhow ;) Here is a dependency-free variable-order double pendulum simulation in about 120 lines of Python. Have you seen the equations of motion for this system? As usual, this is based on code that I have provided here, but trimmed for maximum impact. Can you see...
  29. jishnu

    Python Doubt regarding a basic Python operator

    Hi everyone, I am beginner in python programming. So many doubts are being generted in the learing process Can anyone please explain me how the bitwise NOT (~) operator actually works on values. I have attached a screen short of my textbook (unofficial) with this post and I am confused how...
  30. N

    Python How to plot integration equation using Python?

    I have a few of integration equations and need to convert it into Python. The problem is when I tried to plot a graph according to the equation, some of the plot is not same with the original one. The first equation is the error probability of authentication in normal operation: cond equation...
  31. K

    Python Perform an image deconvolution using FFTs and Python

    Homework Statement [/B] This problem is from Mark Newman's Computational Physics, problem 7.9, found at http://www-personal.umich.edu/~mejn/cp/exercises.html. The problem gives us a blurry convolved image, according to a Gaussian point spread function and our objective is to deconvolve it to...
  32. N

    Python How to fix the error probability plot in Python for MIM and PNS attacks?

    I have several equations and need to convert it into Python. The problem is that I tried to plot a graph according to the equation. However, the graph that I get is not the same as the original one. In the paper, the equation of error probability for MIM attack is given by: First Image Second...
  33. TachyonLord

    The order of calculating velocity and position alters the solution?

    So I tried solving the differential equation for a spring - mass system using Euler's Algorithm in Python. The equation being d2x/dt2= -4π2x (The equation was obtained by Dimensional Analysis) here x and t are both dimensionless equivalents of position...
  34. D

    Python Python program to calculate Kirkwood−Buff Integrals

    I want to write a python program to calculate the Kirkwood−Buff Integrals. The equation is as: G=4π∫0 ∞ r 2 [g(r)-1] dr I have the g(r) values. Any suggestions are highly appreciated. Thank you.
  35. Jozefina Gramatikova

    Python Python: Simulation of the Solar System and Total energy

    Homework Statement I have a project to make the Solar system on Python, which I have done, but they also require from us to calculate the total energy of the system. We don't have to make the orbits of the planets elliptical, they should be circular and I believe I made them like that. Since...
  36. J

    Python Physics books with Python examples

    Hello, I have found two books that show physics branches with python examples: This is for mechanics: https://www.springer.com/us/book/9783319195957 The other on oscillation and waves: https://www.springer.com/la/book/9783319723136 I see in these books that the University of Oslo is doing...
  37. Jozefina Gramatikova

    Python Simulating Gravitational Interactions in a Particle System

    I have a project to make the solar system. I am trying to start from somwhere. On the notes it says that we need to start by creating a System of Particles Two-body simulation (Circular motion) Implement Gravitational acceleration Each particle (planet) could have its own field. I.e. Each...
  38. J

    Python Contour plot of Earth's magnetic field in Python

    The Earth's magnetic field is cylindrically symmetric and can be described using cylindrical coordinates, (ρ,z,φ). The components of the magnetic field are given by: (B_φ) = 0 (B_ρ) = −∂A/∂z, (B_z) =(1/ρ) * ∂(ρA)/∂ρ. The vector potential for a dipole field is given by (A_φ) = (B_e)(ρ) *...
  39. NihalRi

    Python Python 3.0 , encoding="utf-8" for encryption

    I had recently upgraded my version of python from 2 to 3. I had a program that encrypted a text file by converting a character to its Unicode value, altering it and then changing it back to a character using the ord() and chr() methods. This does not seem to work with python 3 and I was...
  40. m4r35n357

    Python Lorenz ODE solver in 35 lines of pure Python

    Features: No external dependencies. Arbitrary order simulation (accuracy limited by float precision). No finite difference errors. Can be extended to arbitrary precision with gmpy2 and two more lines. Enjoy! Parameters: order step size number of steps initial conditions (x, y, z) parameters...
  41. Arman777

    Python How can I adjust the range and scaling for a cos function in Python?

    r = np.arange(0,400,0.1) t = np.cos(r)+10 plt.plot(r,t) How can I use the range of the cos function to look like this
  42. jdawg

    Python How to Modify Python Dice Rolling Game to Accept User Input for Number of Rolls?

    Homework Statement I want to prompt the user to input how many times they want to roll a die, then generate a random number between 1 and 6. I then need to print what their number is and if it is even or odd. The code I posted below is what I came up with for a single die roll that allows...
  43. I

    Python Different answers for division in Python 3

    Hello Consider the following code in Python3 n = 226553150 m = 1023473145 n*m = 231871064940156750 int(n*m/5) = 46374212988031352 n*m//5 = 46374212988031350 Now since ##n*m## is divisible by ##5##, both should be give the same answer. But the first is wrong and second is correct. What is...
  44. M

    Python How to drop rows when there is a length mismatch?

    I am trying to drop the series size so that it matches the size of the dataframe as I need to copy the index value of the series into the df but I am getting mismatch errors. df has a size of 100 but time has a size of 200 so I want to remove the extra rows in time to match df. how can i handle...
  45. M

    Python How to plot timeseries data in Python

    I have a dataframe that looks as attached. What I aiming to do is to plot the lines for each type where if it is for type A, I want to be able to have two lines in the graph that shows the trend for type A. I was not able to find any examples online especially with the format of the data in this...
  46. astroman707

    Python What's wrong with my if-else statements in Python 3?

    Goal: I'm trying to allow the user to input varying spellings for certain auto services, and still have my code work properly. My goal was to use the if-else statements to ensure that if the user misspelled a service, the code could correct the error by changing the variable assignment to the...
  47. opus

    Python Python troubles- says I'm using a string in arithmetic

    Homework Statement I'm making a program to display what I have posted in the image and my program needs to look just like it. The idea is to have an employee enter information such as their pay and hours worked. Then taxes get calculated and it shows a net amount that the employee has made for...
  48. M

    How to plot timestamps within a row?

    i have a dataset that has the timestamp data within each row and I am trying to plot the values to see the distribution but have no idea how to do it if the data is presented this way as attached. any ideas? thanks
  49. archieab

    Converting PyGame 2 axis joystick float to 360 angle

    I would like to convert my joystick's two axis float (horizontal and vertical) to a 360 angle that can be used to set a players direction in my game. From my research, I've found the best route to take is using Atan2. Variables: self.rot = 0 horaxis = joy1.get_axis(0) veraxis = joy1.get_axis(1)...
  50. M

    Python How to calculate rows where it has values in at least 3 columns

    I am trying to count number of rows that has values in at least 3 columns so the output based on the image shared should be 4. I tried using the code below but it is resulting in the same shape as the whole table which is 7. counts = df[(df[['a', 'b', 'c', 'd]] != 'no_label').count(axis=1) >= 3]
Back
Top