What is Python: Definition and 655 Discussions

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. starstruck_

    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...
  2. W

    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?
  3. 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 =...
  4. C

    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))...
  5. JD_PM

    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...
  6. 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...
  7. m4r35n357

    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...
  8. caffeinemachine

    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...
  9. 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...
  10. JD_PM

    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.
  11. websterling

    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...
  12. K

    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...
  13. C

    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...
  14. Othman0111

    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...
  15. GoldenBear

    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...
  16. Eclair_de_XII

    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...
  17. 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...
  18. W

    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...
  19. 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...
  20. W

    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?
  21. 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
  22. 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...
  23. jishnu

    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...
  24. N

    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...
  25. K

    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...
  26. N

    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...
  27. 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...
  28. D

    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.
  29. Jozefina Gramatikova

    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...
  30. J

    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...
  31. 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...
  32. J

    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)(ρ) *...
  33. NihalRi

    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...
  34. m4r35n357

    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...
  35. Arman777

    Python Graphing a cos function

    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
  36. jdawg

    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...
  37. I

    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...
  38. 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...
  39. M

    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...
  40. astroman707

    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...
  41. opus

    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...
  42. 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
  43. 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)...
  44. 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]
  45. M

    Python not recognizing MAX value in a list

    i have a value that is generated as the max value for example from this list [0.6000001, 0.3, 0.3, 0.4] clearly the maximum value is 0.6000001 but python does not seem to be able to recognize this value as the maximum. i have tried so many ways to solve it but to no avail. even when changing...
  46. M

    Python How to check that none of the values are equal?

    the code below intends to take the maximum value that is calculated for each of the variable but after the max value is obtained I am not sure how to ensure there are no 2 or more values are the same in the if else loop as if 'a' has the max value of 3 and 'b' also has the max value of 3 then...
  47. M

    Python Problem with appending a dataframe after a loop

    I am iterating over 2 variables below and after the calculation are done, i'd like to append the dataframe to add the rows after each iteration, but what is happening now is that the row is getting replaced instead of getting added. pre = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] post = [0, 1, 2, 3, 4...
  48. M

    Python How to compute the percentage of values based on multiple columns

    I have a dataframe as shown in the picture and what I am trying to do is to calculate the number of occurrences based on the values in 2 columns and then calculate the percentage of the occurrences. I have tried the following code but it gives me a zero value in the end and i don't know why...
  49. M

    Python How to create a Multi-index dataframe

    I would like to generate a multi index dataframe that looks like the image attached. how do i do this in python? I tried this approach but it doesn't give me the output as expected: https://stackoverflow.com/questions/28289440/creating-an-empty-multiindex
  50. M

    Python How to convert tuple values to strings?

    i have a column in a dataframe that contains values in the form or tuples (example: ('A',) ) and I want to convert these values to string format so that ('A',) becomes 'A' How do I do this in python for a dataframe? Thanks.
Back
Top