What is Python: Definition and 648 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. F

    Iterators and generators and the data they generate

    Hello, I have been focusing on iterators and generators and I understood a lot but still have some subtle questions... An iterator, which is a Python object with both the __iter__ and the __next__ methods, saves its current state. Applying the next() method to an iterator gives us one item of...
  2. ergospherical

    Drawing from a PDF in python

    Some python function f(x) defines an (unnormalised) pdf between x_min and x_max and say we want to draw x randomly from this distribution if we had the CDF F(x) and its inverse F^{-1}(x), we could take values y uniformly in [0,1], and then our random values of x would be x = F^{-1}(y). but...
  3. F

    Python Socket library to create a server and client scripts

    Hello, I have been experimenting with the socket library in python creating small scripts, one called server.py and the other client.py, that can communicate with each other using a TCP protocol. The server script has an infinite loop that listens for request from the client.py script and...
  4. S

    Python Stop current Python REPL command, but keep REPL session open?

    If you just typed in a command into the Python repl, and it is stuck in a synchronous "waiting-for-something-to-happen", how can we terminate just that command and return to the same repl session? For example, say we typed websocket.recv() and the websocket is waiting for a message... how can...
  5. ergospherical

    How to store a large data-set in a "grid" in Python/NumPy

    Say I have n parameters X1, X2, ..., Xn, and to each "grid-point" X = (X1, X2, ..., Xn) I want to associate a value f(X). So in the end I will have a structure like an n-dimensional matrix. Assume this data-set is going to be very large, i.e. each parameter Xi ranges over hundreds or thousands...
  6. robotkid786

    Intro Physics Learn Python: Top Book Recommendations for Beginners

    I'm looking at a book called python crash course for beginners (eric mathes), does anyone have experience of using this book or any other book that you would recommend for learning python if not that, is there a specific course you'd suggest that isn't in book form? I'm completely new to...
  7. robotkid786

    Physics How important is python for theoretical physics?

    Hey guys, I'm a first year student studying theoretical physics in England. My physics modules include a fair bit of python programming and I want to apply to ICGs cosmology PhD in England. Can I escape learning python by choosing maths modules?
  8. tehsportsmaen

    I Two-Mass Oscillator: Plotting Amplitudes Over Frequencies in Hertz

    Idea: Given a system of two coupled oscillators in which 2 masses are connected to a spring in the middle. Each of the two masses is coupled to another spring on the left and right, which have fixed ends but are not connected to each other. So we have 3 springs, two masses and the springs also...
  9. F

    Docker and Containers: Understanding the Basics and Common Doubts Explained

    Hello, anyone on Physics Forums using Docker? I have understood the overarching idea behind Docker (packaging code, dependencies, etc. into a container that can be shared across OSs) but I have some doubts: I am confused about the base image line of code in the Dockerfile (which is simple text...
  10. D

    Is there a quick way to put quotation marks around strings in an array?

    Hi everyone I'd like to cut and paste a list of words into an array. I'll need to put quotation marks around them all. Is there a way to do this other than to go through each word one by one? Thanks
  11. Eclair_de_XII

    Job Skills I know that this is about the hundredth topic I've made about this, but...

    t I'm feeling lost. Currently, I'm trying to learn how to do web-development stuff in Python, so that I can have a project to show-off to prospective employers. I'm also aware that I may be deluding myself into thinking that one project is all it takes to get noticed. Moreover, I just lack...
  12. R

    How to Convert TMESH Data to Text Files in MCNP6 Using Python"

    I would like to analyse mdata of tmesh in MCNP6 by python, but I am struggling how to convert mdata (unformatted binary) to any text file in python. I used GRIDCONV but it's not suitable for automations. I also used scipy.io.Fortrunfile but could not convert the file because I was not sure...
  13. F

    I Is there a better way to calculate time-shifted correlation matrices?

    Hello everyone. I have four thermometers which measure the temperature in four different positions. The data is distributed as a matrix, where each column is a sensor, and each row is a measurement. All measurements are made at exactly the same times, one measurement each hour. I have...
  14. F

    How do Jupyter notebook components work together?

    Hello everyone, As mentioned in past threads, jupyter notebook is a popular application that is used to code in Python (and other languages as well). The jupyter notebook installation includes 3 software components working together: 1) kernel: it interact with the web server 2) server: web...
  15. F

    Clarification about dir() in Python

    Hello, Simple clarification about the built-in function dir() if possible: if we don't provide any argument, i.e. we use the function simply as dir(), the function displays the namespace of the function, of the module, etc. However, if we provide an input, the function dir() displays a list...
  16. VVS2000

    I Finding the difference in Helmholtz free energy using thermodynamic integration

    If there any solved papers or even python simulations to find this please share I understood the process of thermodynamic integration but computationally I want to see how this integration of average of derivative of coupled potential energy is done
  17. J

    I JC Model in Python: Advice & Feedback Needed - Jon Poplett

    Good afternoon! I am fumbling my way through setting up a JC model in python, I was hoping I could get some feedback on it please. I just want to make sure everything looks good and the data I am collecting is valid. Any advice or feedback would be very welcome...
  18. Leo_Chau_430

    Excel Web Scraping Program

    My code is as follow: import pandas as pd from bs4 import BeautifulSoup import requests import os url = 'https://www.goodschool.hk/ss' response = requests.get(url) html = response.content soup = BeautifulSoup(html, 'html.parser') school_items = soup.find_all('div', {'class'...
  19. person123

    My Python Library For Finite Difference Method

    I recently made a Python library for modelling (very basic) finite difference problems. The Github readme goes into details of what it does and how it works, and I put together a Google Colab with some examples (diffusion, advection, water wave refraction) with interactive visuals. I'd love to...
  20. Vick

    Fortran Can Fortran 77 Code Be Used to Debug Python Code for Solving ODEs Using Radau5?

    Hi, I have a piece of Fortran code but I'm not Fortran literate. I'm trying to translate it into Python. I have already made it, but I need someone who can run the Fortran code to compare the values of the variables.
  21. F

    Create a Mask-RCNN Model in Python for Smart Parking Systems

    Homework Statement: I am trying to write a Python code to do a project about smart parking system. I want to create a Mask RCNN model to detect the vehicles in the parking slots. My code is attached below, I got an error in the last line (creating Mask_RCNN model) and do not know how to solve...
  22. C

    Graphing a piecewise function (Python)

    I am trying to write a python script to plot the function, Where ##V_0 = 5~V## ##t_0 = 10~ms## ##\tau = 5~ms## My script that I have written to try to do this is, Which plots, However, the plot is meant to look like this with the horizontal line. Can someone please give me some guidance to...
  23. S

    Help with Histogram and Boxplot in Python

    I could really use some help here, I am a transfer student so my course load is all out of order. I have a statistics course that requires me to use Python to solve this one question (the 2 parts shown below). I never took any sort of coding before, I don't know where to even start. Can anyone...
  24. ergospherical

    Speed of function vs lambda calls in python

    An observation I made earlier- something like def f(...): ... return ... def g: ... = f(...) was quite a bit slower than doing def g: f = lambda ... : ... ... = f(...) any reasons why?
  25. B

    Python FineTune the Pixel2Style2Pixel model with my custom data set

    I want to fine-tune the Pixel2Style2Pixel model with my custom data set, but I keep getting an error when I'm trying to load in the pre-train weights. Here is my code : # Load the pre-trained model os.chdir("/content/pixel2style2pixel") from models.psp import pSp config = { "lr": 0.0001...
  26. Gwen

    Thermal lattice Boltzmann model ignoring source term -- python code help please

    LBM model for phase change- relevant equations found here. Also here. #Thermal LBM #solves 1D 1 phase phase-change #D2Q5 Lattice nx=100 # the number of nodes in x direction lattice direction ny=5 # the number of nodes in y...
  27. F

    Automatic parking slots detection using Python

    TL;DR Summary: How to automatically detect the parking slots using Python? I have a Deep Machine Learning course and would like to do my course project about "Available Parking Slots Detection using Deep Machine Learning Based on Image Processing". My plan is to split the project into two...
  28. jim mcnamara

    Codon, new Python compiler

    See this story here in a press release from MIT: https://news.mit.edu/2023/codon-python-based-compiler-achieve-orders-magnitude-speedups-0314 Basically, any working Python module can be compiled one time only, and then run 10+ times faster than interpreted code, with no further changes to...
  29. Arman777

    GTRPy - A python package for General Relativity Related Calculations

    Hello, everyone I am now working on this project quite a while now and I just wanted to share it with this forum, which I was a member for a long time. I am working on a python application about GR and I believe I managed to create a very user-friendly layout. It's called GTRPy, and it allows...
  30. S

    Comp Sci Plot periodic function with Fourier coefficients

    I have plotted the function for ##T=15## and ##\tau=T/30## below with the following code in Python: import numpy as np import matplotlib.pyplot as plt def p(t,T,tau): n=np.floor(t/T) t=t-n*T if t<(2*np.pi*tau): p=np.sin(t/tau) else: p=0 return p...
  31. alpha

    Solving Linear Programming problems in python PulP

    Okay so far I have come up with the following: The objective function is: 30LADA + 40LAHO + 50SADA + 40SAHO + 110DANY + 125DACH + 105HONY + 115HOCH (to read this please see the table above as I have just used the first two letters of each except NY which I have represented by NY). In these I...
  32. B

    Python Pix2pix: Image-to-image translation with a conditional GAN

    So I am trying to do this tutorials but I want to use my own dataset. I am having problems "Build an input pipeline with tf.data." My question is about their code: def load_image_train(image_file): input_image, real_image = load(image_file) input_image, real_image =...
  33. Grinkle

    Are Python strings truly immutable?

    I am using "Introducing Python" (Lubanovic) to teach myself Python. I read that Python strings are immutable, then I see code like this - string1 = 'base_val' string1= 'new_val' not throw up an error. A little investigation shows me that the interpreter created two strings and string1 is a...
  34. A

    A Space-time diagram help

    I am trying to replicate the space time plot (the 2nd plot with Proper distance vs Time) as in this thread: space-time I wrote everything in python using the astropy cosmology package. Everything went smooth, but I am stuck at plotting the light path on the 'purple path', as per the above...
  35. M

    Does this python script match the math?

    Hi PF! I've posted a bunch lately and you have been SO helpful (seriously, thank you all). Can you corroborate if my python script below matches the math? I'd seriously appreciate it! The math: $$\max_{x\in [0.7,1)}F(x) : F(x) := \sum_{t = 250}^{750} \log\left( P_{\nu=3} \left(...
  36. Sciencemaster

    I Calculate Gaussian Curvature from 4D Metric Tensor

    I've been trying to find a way to calculate Gaussian curvature from a 4D metric tensor. I found a program that does this in Mathematica using the Brioschi formula. However, this only seems to work for a 2D metric or formula (I would need to use something with more dimensions). I've found...
  37. M

    MATLAB Can I run sections of code independently in Python and C++ like in MATLAB?

    Hi PF! I typically code in MATLAB. Here, if I run the following program %% Section 1 x = 5; y = 2; %% Section 2 z = x + y; everything works. But now let's say I wanted to change line 5 to z = x - y. In MATLAB this is simple: I can simply change line 5 and rerun section 2. Is there a way to...
  38. M

    Should users confirm their account deletion before it is processed?

    Hey! 😊 I have written a code in Python for a server to search for movies. At the site for the user I have added at the html template the options to change the password and to delete the account. For this do I have to write a separate html or a separate endpoint for these ones or can I write...
  39. TheJP78

    Building a Solar System simulation with python

    Hey'all. First of all, I'm not fluent in English, so forgive me for the spelling mistakes. So, I'm trying to make a simulation of a solar system using python 3.9. It's not complicated, but my teacher wants me to do it using the Basic Verlet method, and that's what is bugging me. He told me do do...
  40. M

    One-line Python Code that returns a sequence of integers

    Hey! 😊 I want to write a one-line Python generator or iterator expression that returns the sequence of integers generated by repeatedly adding the ascii values of each letter in the word “Close” to itself. The first 10 integers in this sequence are: 67, 175, 286, 401, 502, 569, 677, 788, 903...
  41. Graham87

    Comp Sci Orbit of the Earth - numerical methods leapfrog

    I am attempting this homework exercise part b). I've modified my code but I get error overflow message. My goal is to modify my code so it returns kinetic and potential energy of Earth's orbit. I made a new f(z,t) and modified the rows 99 and 100 with dz[2]=-G*M*m/r, and dz[3]=0.5*m*y**2 but...
  42. Graham87

    Comp Sci Orbit of Earth: Plotting Trajectory

    I am attempting this homework exercise but my plot does not show the whole trajectory. I don't know if it is something wrong with my equations or if it is a plotting matter. Cheers!This is my code:import matplotlib.pyplot as plt import numpy as np import scipy.integrate as spi G =...
  43. S

    Python, unittest.mock : Getting object & method names from method_calls

    Let's say that my_mock.method_calls gives me this array: [call.thing.pop(3, 4), call.thing.bob.smash(6, 7), call.thing.jig.slurp(4)] How can I extract the names 'thing', 'pop', 'bob', 'smash' etc. from this array?
  44. M

    Python - HTML : Isn't this a dictionary ?

    Hey! 😊 I have written a program in Python where API calls to the server to get currency exchanges. Now I want to add a part for the user, i.e. with html. The endpoint is : @route_rates.route("/all/") def get_all(): return render_template("currency.html", my_currency =...
  45. R

    In Python flask I am trying to set up the SMTP for emails in outlook

    I am trying setting up flask email for outlook. I had it working with gmail I found this link https://superuser.com/questions/1521236/how-to-allow-less-secure-app-access-in-microsoft-email I tried MAIL_SERVER= 'smtp.office365.com' MAIL_PORT = 587 MAIL_USE_TLS = True...
  46. M

    Python - Endpoint : Can the function not return an array of dictionaries ?

    Hey! 😊 I am trying to write a code for a server in Python and I got stuck. I gave as an input a csv file and using pandas we get a dictionary where the titles are the keys and the inputs are the values. From that we get the below : I have written the below endpoint to get all the...
  47. M

    Python: Semidefinite program with CVXPy 'Error parsing inputs'

    Hi, Question: Why is the error 'Error parsing inputs' in CVXPy occurring? Context: I am trying to solve a semidefinite program in CVXPy (using Google Colab). I went to the documentation (HERE) and I copied the example code into a cell. It doesn't work for some reason and I don't understand...
  48. ergospherical

    Algorithmic trading with python

    If you have used an online course pertaining to the title, could you write a short review? Not looking for a book.
  49. M

    Import python list from .txt file into Mathematica

    Hi PF! I am trying to import k.txt file into Mathematica as a list of numbers. The k.txt looks like this: [5.315967917338153e-06, -3.204321972222162e-08, 3.6041782425371564e-09, -3.853442465663655e-08, 8.699510604529962e-07, -1.4284341965847237e-08, 2.855341882658808e-09...
  50. user366312

    Polymer simulation source code in C++ and Python

    I am absolutely new to Polymer simulation. I am trying to understand the simulation by analyzing source code written by others. Can anyone tell me what are the differences between the following three source code in terms of their objectives? Monte-Carlo-simulation-of-polymers...
Back
Top