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

    Functions, naming conventions in Python

    Sometimes, when I code something, I am naming the local variables in the function same as the global variable. Such as, my_var = 13 def iseven(my_var): if my_var % 2 == 0: return True return False print(iseven(my_var)) As you can see my_var is defined globally but also used...
  2. Wrichik Basu

    Solving the heat equation numerically using Python

    I want to solve the heat equation numerically. The equation is: $$k \dfrac{\partial^2 T}{\partial x^2} = \dfrac{\partial T}{\partial t}.$$ This is a parabolic PDE. Following this pdf (specifically, equation 7 given on page 3), I wrote the following Python function to implement the explicit...
  3. C

    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...
  4. 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...
  5. V

    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) ...
  6. Arman777

    Python Packages to Calculate orbits in Schwarzschild Metric

    I am looking for a Python Code/Package to calculate the orbits of the time-like and null-like particles in Schwarzschild metric (in spherical coordinates) Does anyone know such package ? Note: I am mostly looking for packages to calculate the RIGHT side of the given images (i.e the orbits...
  7. W

    Python: Are Terms in this List Monotonic?

    Given a list [ a,b,c,..., z] in Python, write a program to determine if the terms are monotonic or not. I can do either , and combine theminto a long, clunky program, but trying to see if I can find a succint way of doing both. I have heard that using ' Nums' may do it,but it seems too...
  8. 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...
  9. W

    Letter-based Strings not Recognized as Strings in Python Reversing

    Hi, I have a simple Python algorithm in my Jupyter notebook , to reverse a string. It works well on numerical strings, but when I try to reverse a letter string, I get an error message, e.g., the string abc, I get the error message: name 'abc' is not defined This is my Python code def...
  10. W

    Overly large Python Jupyter Notebook (.ipynb) files

    Hi all, I was looking up my virtual file manager in Python Jupyter and in the listing of notebooks; all similar to each other in size and scope , some files stand out in terms of size for no apparent reasons. I have some 40 notebooks ; all- but- 2 ranging from 10kb to 284kb at the extremes , and...
  11. G

    Does anyone know about python flask and wtf forms?....

    from flask import Flask, render_template from forms import RegistrationForm @app.route("/register", methods = ['POST', 'GET']) def register(): forms = RegistrationForm() return render_template('register.html',form=forms) from wtforms import Form, BooleanField, StringField...
  12. 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...
  13. 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)...
  14. 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...
  15. PeroK

    What happens when large integers are involved?

    I've written a program to factorise large numbers (although not that large). The following arithmetic operation goes wrong: x= int(912_321_155_211_368_155/(5)) The result is 182_464_231_042_273_632 Which is clearly not right (should end in 631). The maximum integer on the 64-bit version is...
  16. F

    Understanding Pickle & JSON Serialization in Python

    Hello, I understand that pickle and json are two different modules to serialize Python data. Serialization means to convert an object into a string. When using pickle, we convert the Python data into a binary file. With json, the data is converted into a json file which is essentially a...
  17. PeroK

    Problem importing matplotlib in Python

    I'm running Python 3.8.3 on Windows 10 and was have installed matplotlib, but I can't get it to work. If I try import matplotlib then first it seems to spit out some output (always the same) from a couple of basic test programs I wrote (which is really weird), then just gets a bunch of errors...
  18. F

    Understanding where pip saves the downloaded Python modules

    Hello, I have been trying to figure out where things are stored in Windows. For example, I have two versions of Python, one is stored in the PYthon37 folder and one in the Anaconda3 folder. See below: I have been using pip at the command prompt to install packages/modules and when typing at...
  19. Wrichik Basu

    What's wrong with this Python program on Euler's forward algorithm?

    Here is the function that I have written: import numpy as np def ode_euler_forward(odefun, y_initial, x_range, num_steps): """ Solves a system of non-stiff ODEs using Euler's forward algorithm. Parameters ---------- odefun : callable(x, y1, y2, ...) The function...
  20. Arman777

    Is there a Python function that finds an unknown inside an integral?

    I have a integral with unknown h. My integral looks like this where C, a, b are constants F(x) and G(x) are two functions. So the only unknows in the integral is h. How can I solve it ? I guess I need to use scipy but I don't know how to implement or use which functions. Thanks
  21. F

    Python Dot Notation: Access Functions, Classes, Objects & Variables

    Hello (again). I have become quite familiar with the dot notation in Python. The dot "operator", assuming operator is the right term, seem to have many uses. For example: 1) After an instance name, it can be used to access instance attributes and apply instance methods to the object/instance...
  22. F

    Exploring Python Special Methods & Classes

    Hello Forum, In Python, methods are functions which are defined inside a class. Python has many reserved keywords and built-in functions like print(), add(), type(), etc that we commonly use even when we don't create classes, instances, etc. Whenever we use an operator (like + or - ) or a...
  23. appletree23

    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...
  24. 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...
  25. F

    Questions about the for loop, iterable, iterator in Python

    Hello, I understand that a ##for## loop is intended to repeat the same code a finite and specified number of time. The loop syntax is for i in iterable: statement(s) for = keyword i = counter variable iterable = any iterable (list, tuple, dictionary, range()) statements = body of the...
  26. Z

    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
  27. theycallmevirgo

    A useful software: schematics drawing package for Jupyter (python)

    Just wanted to give a shoutout to SchemDraw, a FOSS circuit schematic drawing package for Jupyter(Python), made by a PhD at Sandia Labs. It's purely drawing, not simulation of any kind, but given Python's numeric and symbolic superpowers it's easy enough to bolt-on that functionality. If...
  28. Arman777

    How to Continuously Iterate Through a Linked List in Python Using urllib

    import urllib.request import urllib.request request_url = urllib.request.urlopen( 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345') print(request_url.read()) I have a code somthing like this which prints "and the next nothing is 44827" Now is there a way to get...
  29. jack action

    Running Electrum in Python from the CLI on Ubuntu 20

    I'm trying to run electrum (written in python) from the command line on Ubuntu 20. I have 2 similar computers. The first one has version 4.0.4 and once in the electrum folder, I type electrum (the name of the executable file) and it executes whatever command I ask for. My problem is with my...
  30. k1120

    Python code to calculate the age of the Universe using the Hubble constant

    honestly just need some help here i understand the physics just not how to code it or the syntax of python
  31. Arman777

    Looking for online/book Problems about the Python Classes

    I started to learn classes in python and I am looking for problems about them. Are there any good online sites that I can find problems about them. If they also contain solutions, that would be great, but if not that is also okay. Problems can have the form like An administrator is a special...
  32. Arman777

    İmport a python function inside a subfolder

    I have a project folder called Projects and inside that folder I have a file called my_functions.py. Now I have a folder named Project 1 and inside there is another python file called test.pySo it is something like -Projects- my_functions.py -Project 1- test.py Now I...
  33. T

    First, second, third and fourth generation + Python and Javascript

    Good Morning I have understood, as a general rule and category (and I realize all such attempts to categorize are fraught with danger), the four generations of languages, from as machine (first generation), to assembly (second generation), to compilable (third generation; e.g., C, FORTRAN) and...
  34. E

    Online course for probability and statistics with emphasis on python

    I have been looking for a way to learn probability and statistics online and have searched but found nothing yet. I am looking for a course on probability and statistics that will not only teach me the basics but all there is to know about the subject. I would love it if the visualizations are...
  35. Mikkel

    I How Does Finite Size Scaling Reveal Cluster Behavior in 1D 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...
  36. Z

    Cprev and Self.C are referring to the same NumPy

    I've encountered this really weird bug in Python. Below is a snippet from a class method. The error occurs where I've placed the two print statements. The update method has absolutely nothing to do with Cprev. The update function changes the value of the attribute self.C. However, the two print...
  37. Isaac0427

    Redundancy in __init__ in python?

    Here is an example code in python, describing a class of fruits: class Fruits(object): def __init__(self, color, taste): self.color = color self.taste = taste If, in general, we ALWAYS do this: class ExampleClass(object): def __init__(self, property1, property2)...
  38. F

    Understanding Python Module Installation with Pip

    Hello, I understand that modules are essentially Python file save as .py. These files contain both functions and/or classes. To use them in our programs, we must use the keyword import. However, this works only if the module is available, i.e. already installed in the standard Python library...
  39. 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...
  40. Isaac0427

    Trying to understand Why () in Python

    I am still on the basics of python, so the odds are if you use a lot of fancy terms I will not understand the answer yet. It is just really confusing me. Thank you!
  41. F

    Objects in Python: Integer, Float, List & Classes

    Hello, I get that everything (almost?) in Python is an object. Objects are instances of classes with associated attributes (i.e. characteristics, properties, features) which are essentially variables. Objects also have associated methods (i.e. functions that act on the object or make the object...
  42. F

    Nested structures and indentation in Python

    Hello! In the context of Python, indentation is very important and mandatory. The entire code is separated into blocks and each block has its own indentation. Two blocks with the same indentation belong are the same block unless the blocks are separated by a block with less indentation...
  43. F

    Python IDLE and print function....

    Hello, While using the IDLE editor, I noticed that it is possible to simply type the variable name, list name, dict name and view its content without using the print() function...For example, if the variable a=5, then I would expect print(a) to output 5. And it does. But I can also simply type...
  44. Amathproblem22

    Python & Line Sensor (IR) for Robot Project

    I'm making a robot the will follow a black line and I need some assistance does anyone here have experience with python and line sensors.(IR) If anyone does I can elaborate on my issues more. Thanks
  45. W

    Python Data Structures: Guessing a Number

    Hi all, Trying to right a program in Python asking user to guess a number ( integer in finite range) until they make a correct guess, though I want to warn user when guess is too high --asking that they choose a lower number ,and same for when the guess is low, asking them to choose a higher...
  46. 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...
  47. PeroK

    Starting to Learn Python: Development Tools and Environments

    I finally decided to learn how to program in Python. The basic syntax seems easy enough, but I have a few questions: There is a dizzying array of editors and IDE's out there. What is a good option to get started? I've never programmed (or done anything technical) on Windows. Is there any...
  48. W

    Elementary Python Questions: Data Frames, k-nary functions

    Hi All, A couple of questions, please: 1) Say df is a dataframe in Python Pandas, and I select a specific column from df: Y=df[column].values. What kind of data structure is Y? 2) I want to find the sum of two numbers: Def Sum(a=0,b=0): return a+b If I want to find a sum over sum data...
  49. 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...
  50. Eclair_de_XII

    Finding a local max/min of a function in Python

    Okay, so my algorithm looks something like this: ==== 1. Locate mid-point of the interval . This is our estimate of the local max. 2. Evaluate . 3. Divide the main interval into two subintervals: a left and right of equal length. 4. Check to see if there is a point in the interval such that ...
Back
Top