Python Definition and 189 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. 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...
  2. 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 =...
  3. 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...
  4. Sciencemaster

    I Is there a program that can solve for Gaussian curvature of a Metric?

    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...
  5. 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...
  6. 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...
  7. Graham87

    Comp Sci Orbit of the Earth

    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 =...
  8. S

    Python 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?
  9. R

    Python 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...
  10. 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...
  11. 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...
  12. bikashdaga

    Static variable in static method - how to use?

    I wanted to declare a local variable inside a static method main(). My code looks like this - class Operator { static int a; public static void input() { Scanner in=new Scanner(System.in); System.out.println("Enter the number:"); a=in.nextInt(); //this is...
  13. R

    I am trying to use alembic in python flask and it is not working

    https://blog.miguelgrinberg.com/post/how-to-add-flask-migrate-to-an-existing-project I am using Visual Studio Code and have a database file already created called test.db. My environment variables for test.db name is SQLALCHEMY_DATABASE_URI and the value is sqlite:///test.db In the actual code...
  14. A

    Image comparison software (similarity and differences)

    Images comparison What are the best softwares available for comparing two images having similarity and differences? Two photos each of Margaret and Enid. 1 Margaret's first photo with her second photo comparison. 2 Enid's first photo with her second photo comparision. 3 Margaret's first...
  15. B

    Python Input error for LSTM neural network

    Hi everyone, I have to classify a DNA sequence with a LSTM neural network but I have a problem with the inputs shame. Both the sequence and the class are encoded with One Hot Encoding and my code is this: import pandas as pd import numpy as np data = pd.read_csv('splice.data', header = None)...
  16. B

    How to make progress in programming classes?

    Hi everyone, Hopefully I'm writing this in the correct part of PhysicsForum. Here is my problem: I'm really struggling with my programming class (basics of python3 - loops, dictionaries, numpy). What I did this semester: 1. Participated in every class 2. Solved everything our course offered...
  17. C

    Comp Sci Evaluating if a given integer can be calculated from a list containing numbers and operators (Recursion)

    Here's what I've done: Mentor note: replaced icode tags with code=python and \code pair. def valid_braces_placement(s, L): if len(L)==0: return False string = '' for element in L: string = string + str(element) D = ['+','-','*'] return...
  18. SamRoss

    How can I get the RUN button in Visual Studio Code to turn GREEN again?

    I have been using Visual Studio Code for a couple months now and it has been fine. When I want to run some code, there is usually a little green triangle button in the top right corner that I can click on. A few days ago, that triangle turned white only for Python files (it is still green for...
  19. user366312

    How can I calculate hydrogen bonds in a specific direction w.r.t. a C-

    I need to calculate H-bonds in a specific direction of a C-alpha atom of a protein. And, I need to calculate that from a PDB file. Can anyone give me a general guideline/direction/idea regarding how to do that? N.B. I need to write a python program.
  20. S

    Comp Sci A Question about modulus R in Rabin Karp Algorithm

    Hello, I am learning trying to set up a code that searches for a certain pattern in the text by implementing Rabin-Karp Algorithm. When setting up the Rabin Karp hash function, I have been told that I should set a value q in order to lower the time complexity of the function, and that q should...
  21. D

    Python How does one assess progress when learning a programming language?

    I'm a physics major (Junior) who would like to learn a programming language. Many suggest Python as a good starting language, so let's suppose that is the language I want to first learn. This isn't for employability or general usefulness; rather, I'm just curious. How exactly does one go about...
  22. user366312

    How can I implement a multi-task deep learning neural network?

    I have 3 classes (A, B, and C). I have 6 features: train_x = [[ 6.442 6.338 7.027 8.789 10.009 12.566] [ 6.338 7.027 5.338 10.009 8.122 11.217] [ 7.027 5.338 5.335 8.122 5.537 6.408] [ 5.338 5.335 5.659 5.537 5.241 7.043]] These features...
  23. C

    I Solving 1-D Schrodinger Equation in Python (Scipy) Numerically

    I've tried to make an animation using python to demonstrate the 1-D simple harmonic oscillator and step potential examples. Hope that it can be useful for some of you. Have fun~ :) https://blog.gwlab.page/solving-1-d-schrodinger-equation-in-python-dcb3518ce454 By the way, If you are...
  24. hugo_faurand

    Help with the Python package Scipy and the Z-transform please

    Hello everyone ! I am working on ultrasound scan and the processing of the signal received by the probe. I made the model I wanted and as I do not have an ultrasound scan machine I want to simulate the signal processing. I will do that with the Python package Scipy and the function...
  25. V

    A Adding noise and solving stochastic ODEs in Python

    The Coupled ODE Model Below are my coupled differential equations, where the only variable I try to meddle with is the ITMblood. The motivation here is if I try to increase ITMblood (in the next section I will show how I do it), at some concentration of ITMblood (most likely a very huge one) ...
  26. B

    I Why is (N dot N) different for magnitude than for X, Y, Z components?

    I have to perform a calculation on my data. Here is an example of data from just one time step (data from other time steps would appear as additional rows). X Y Z Total 2 2 1 3 Total = SQRT(X2 + Y2 + Z2). The calculation I have to do is: (N • N), where "N" is an average. I tried...
  27. user366312

    Python Kindly explain this source code for me

    Check this link: How to override the copy/deep-copy operations for a Python object? Can anyone explain, in layman's terms, what is going on in this source code? from copy import copy, deepcopy class MyClass(object): def __init__(self): print('init') self.v = 10...
  28. B

    How to write basic syntax for triangle recursion?

    Hi, I'm new to programming in python [total beginner in programming] and I would like to ask you for your help. Here is what I got so far: import numpy as np import random from math import sqrt p = np.array([(0, 0), (1, 0), (1, (1/sqrt(2)))], dtype=float) t = np.array((0, 0)...
  29. T

    Scientific Computing: Method of Undetermined Coefficients in Python

    In a self learning project I am fooling around book https://faculty.washington.edu/rjl/fdmbook/ I want to do some of the computation myself to better understand the concepts but the book is Matlab based and Matlab is too expensive. Does anyone by any chance have some of the codes provided by...
  30. appletree23

    Comp Sci Finding the stability of a system using Python code

    I'm given this code to plot the system for task 1 where my teacher have used some random numbers just to show us how the code can be used: The code makes a plot that is given below: So my professor just gave us this code and plot without saying anything more. All the students in the class...
  31. B

    Python Minimization likelihood function with parameters

    Hallo at all! I'm learning statistic in python and I have a problem to show you. I have this parametric function: $$P(S|t, \gamma, \beta)=\langle s(t) \rangle \left( \frac{\gamma-\beta}{\gamma\langle s(t) \rangle -\beta}\right)^2\left( 1- \frac{\gamma-\beta}{\gamma\langle s(t) \rangle...
  32. Z

    Comp Sci Tackling Boundary Conditions in Python (Griffins Example)

    How to run a numerical simulation of Laplace equation if one of the boundary condition is like this: $$V(x,y) = 0 \text{ when } x \to \infty$$ I am trying to use Python to plot the solution of this Example 3.5. in Griffins EM
  33. Mikkel

    I One dimensional percolation

    Hello I am struggeling with a problem, or perhaps more with understanding the problem. I have to simulate a one dimensional percolation in Python and that part I can do. The issue is understanding the next line of the problem, which I will post here: "For the largest cluster size S, use finite...
  34. O

    Problem in solving differential equation

    Hello everyone! I was studying chaotic systems and therefore made some computer simulations in python. I simulated the driven damped anhatmonic oscillator. The problem I am facing is with solving the differential equation for t=0s-200s. I used numpy.linspace(0,200,timesteps) for generate a time...
  35. B

    Simulate the temperature inside an aquarium tank

    there's a website to size an aquarium heater or chiller. This is just for learning purposes (not for fish) but I have modified these parameters from default to perform a load calculation on a 100 gallon glass tank... For the tank temperature range I set to be between 150-160 degree F. and a...
  36. Daniel Lima

    Python How to plot a function with multiple parameters on the same set of axes

    I attached a file with some explanations of the variables in the code and the plot that I should get. I don't know what is wrong. Any help will appreciated. from scipy.integrate import quad import numpy as np from scipy.special import gamma as gamma_function from scipy.constants import e...
  37. CrosisBH

    Computing the wave function of a square potential

    The book's procedure for the "shooting method" The point of this program is to compute a wave function and to try and home in on the ground eigenvalue energy, which i should expect pi^2 / 8 = 1.2337... This is my program (written in python) import matplotlib.pyplot as plt import numpy as...
  38. Avatrin

    Creating noise images with Python and OpenGL

    Hi I am learning how to do a line integral convolution with OpenGL given a vector field. So, as a first step, I need to learn how to create an nxn noise image. Are there any good tutorials/books I can use to learn how to do this?
  39. Jozefina Gramatikova

    Visualising a matrix in Python

    As part of a group project, we have been asked to create a code which produces the following matrix: I want to create the graphics of this in a way that looks similar to this: But of course with different number of cells, different colours, etc. The problem is that from what I have found...
  40. S

    Comp Sci Python Assertion Error Help

    I would like to make output only read: Traceback (most recent call last): AssertionError ... without giving the File "<input>", line 1, in <module>
  41. T

    Python Error due to the arrangement of conditions with an IF statement in while loop with an AND operator

    I am currently doing a leet code problem and came across something, I have not noticed before. Here is a sample of the code I am working on. s = "10#11#12" A=[] B=[] i=0 count=0 while i < len(s): if i+2<len(s) and s[i+2]=='#': A+=[(s[i]+s[i+1]+s[i+2])] i+=3 print(i)...
  42. Mikkel

    Python Numerical modeling of a glacier's length -- Coding error(s)

    Hey Physics Forum I am currently doing my bachelor project in geophysics, with focus on the evolution of glaciers in Greenland. My project consists partly of programming, because I want to get better at it. I have, however, hit a wall. I can't seem to figure out what is wrong with my code and I...
  43. B

    Second programming language to get under the belt: python vs C

    Hello everybody, I am a master student in Theoretical Chemistry and I am working in the DFT realm. Both TDDFT and DFT applied to extended systems (eg. using QUANTUM ESPRESSO). Of course I work with these softwares from a end-user point of view, not as a developer. But anyway, even if some of...
  44. L

    Intermediary projects in Python (Biophysics)

    Hello, I am an Undergraduate student looking for ideas for a project in Python. The project should contain a library filled with modules, classes (and preferably something with inheritance), and the unittest module. I would like to do something as follows: First, some kind ob WebScraping to...
  45. antoniacarol

    Python Python Coding-While Loops

    Please help! I am trying to create a Python program for an assignment that will convert Celsius to Fahrenheit and vice versa depending on the input from the user. The numeric conversion portion of the code is working, however, if the user inputs "exit" the while loop is supposed to terminate...
  46. C

    Python How can I evaluate a Chebishev polynomial in python?

    Hello everyone. I need to construct in python a function which returns the evaluation of a Chebishev polynomial of order k evaluated in x. I have tested the function chebval form these documents, but it doesn't provide what I look for, since I have tested the third one, 4t^3-3t and import numpy...
  47. S

    Comp Sci Python: printing every other input using a for loop

    I want my output to read only the integers. Here's my attempt: number = int(input()) for i in range(2, number+1, 2): print(input())
  48. T

    Python Converting List and tuples using str() function

    I am currently working my way through some w3schools python exercise on tuples and lists etc and one question was to write a program to converted a tuple to a string. Now originally I used the str() function on the tuple and printed the result. I then used the string in a for loop for a...
  49. D

    I need my 'fits' image file data to show up brighter than the background noise

    image_data = fits.getdata(alma_image, ext=0) plt.figure() plt.imshow(image_data, cmap='viridis', vmin=-4, vmax=4) plt.xlim(540,640) plt.ylim(540,640) plt.colorbar(extend='both') plt.clim(0, 1) plt.show()
  50. JayZ0198

    Multipurpose software that keeps C, Python, DSP, .... in the same file

    I’ve been looking for a certain type of software that can host programming (preferably C or Python) and other process that I’m going to need such as DSP, DSP filters, diagrams (3D graphs, charts,…), and text editing within the same file. It’s mainly so that I can incorporate and use each one...
Top