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

    Should I enroll in a python course or java? (I’m studying physics)

    Python based course or java course ?. I will be taking an introductory computer programming course . One is python based and the other is java based. The java based course has 2 semesters and goes more in depth with programming . Would it be useful to just take the java courses and get the...
  2. S

    X error correction code in ProjectQ Python

    I have been trying write a code in for error correction. I am new to programming and am unable to understand what is not alright. Can anyone please suggest some explanation? from projectq.ops import All, CNOT, H, Measure, Rz, X, Z from projectq import MainEngine from projectq.meta import...
  3. M

    Running CFD with python and bash: not in agreement

    Hi PF! I'm running a CFD (computational fluid dynamics) program OpenFOAM. Liquid is sucked from a tank, where the velocity at the tank outlet (suction point) is controlled by a python script. The boundary condition for velocity at the outlet is below, line 4 being the velocity prescribed at...
  4. patric44

    Plotting the solution of the central equation using python

    hi guys i was trying to came up with a basic code that could show me the band gaps in a solid after adding the periodic potential term to my solution : $$ E = \frac{ħ^2q^2}{2m} \pm Vg $$ where Vg is my periodic potential , q is the k values in the first billion zone from my understanding if i...
  5. V

    Minimizing a function in python

    The function is f(x)=x5-12x3+7x2+2x+7. I found the minimum of the function and compared the value to a calculator and it seemed okay. But I am confused as to how to incorporate the interval into my code. Has my code already sufficiently answered the question? from scipy import optimize...
  6. V

    Graph tan and arctan with python

    import numpy as np import matplotlib.pyplot as plt x=np.arange(-5*np.pi, 5*np.pi, step = 0.02) plt.ylim(-1, 1) tan=np.tan(x) arctan=np.arctan(x) plt.plot(x,tan) plt.plot(x,arctan) Here is the code I came up with using the guide my teacher gave me, is this correct the way I have done it? Thank...
  7. 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...
  8. V

    Calculating Riemann Sums on Python w/ Numpy

    import numpy as np def num_int(f,a,b,n): dx=(b-a)/n x=np.arange(a,b,step=dx) y=f(x) return y.sum()*dx def rational_func(x): return 1/(1+x**2) print(num_int(rational_func,2,5,10)) Here is my code for the left endpoint, I know this code works because I compared it to an...
  9. 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?
  10. S

    Python: inverse of a block matrix

    I am using the following code. It's returning the block matrix (Z) raised to negative one (think about inputting 22/7 in a Casio fx-991ES PLUS). import sympy as sp from IPython.display import display X = sp.Matrix([[1, 1, 1], [2, 2, 2], [3, 3, 3]]) i = sp.Matrix([[1], [1], [1]]) Z =...
  11. 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...
  12. S

    How to Catch and Print Assertion Errors in Python

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

    Python Why Order Matters in an 'and' Statement

    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)...
  14. V

    Is My Python Bisection Method Code Correct?

    import math def poly(x): return (x**4 + 2*x**3 - 7*x**2 - 8*x + 12) def bisect(f,a,b,tol=1e-6): while (b-a)>tol: m=(a+b)/2 if (f(a)>=0>=f(m)) or (f(a)<=0<=f(m)): b=m else: a=m return (f(a),a) print(bisect(poly,-4,-2.5)) Here is...
  15. 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...
  16. R

    Can I ask some basic Python installation questions?

    I finally decided to do something I've been meaning to do for a couple years, namely learn Python. I opted for a Coursera course sponsored by IBM. They provide a "lab" that has everything you need to write and test code fragments in Python 3. But now I'm at the point of wanting my own...
  17. V

    A derivative/limit calculator using python

    import math def derivative_quotient(f, a, h): return float((f(a + h) - f(a)) / h) if h==0: return "Division by zero is not allowed." Here is my code so far, I am unsure of where to go from here or if I am even on the right track. I am a little confused what it means by "where...
  18. gmax137

    RIP Python Terry Jones: Remembering A Legend

    https://www.bbc.com/news/entertainment-arts-51209197
  19. W

    Python 3 Anaconda:Syntax Error on inexistent line#

    Ok, I wrote a small program P, initially of 16 lines in Jupyter Anaconda in Python 3.7 I deleted the last 4 lines, ending up with 12 lines in P2. Now, I run P2 and I'm told there is a syntax error in (the inexistent) line 14. I restarted the kernel, nothing. I opened another notebook, pasted...
  20. 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...
  21. N

    Python, scipy.integrate.solve_ive, a problem with plotting a graph

    Hi, I have this code that solve the equation of motion of a relativistic electron. from math import sqrt from scipy.integrate import odeint, solve_ivp import numpy as np import matplotlib.pyplot as plt e = 1.602 * 10 ** (-19) E = 10 ** 6 m = 9.106 * 10 ** (-31) def d2vdt2(t,r): t_arr = []...
  22. W

    Getting this Array to be in 2D instead of 1D for Python Linear Regression

    import matplotlibimport matplotlib.pyplot as plt import numpy as np from sklearn import datasets, linear_model import pandas as pd # Load CSV and columns df = pd.read_csv("C:\Housing.csv") Y = df['price'] X = df['lotsize'] # Split the data into training/testing sets X_train = X[:-250] X_test =...
  23. Arman777

    Subscript problem for greek letters in python print function

    I am trying to create a GUI for a phyiscs project and I need subscripts of these things. `H_0`, `Omega_b`, `Omega_dm`, `Omega_\Lambda` `Omega_r` in the form of latex My code is something like this import PySimpleGUI as sg sg.change_look_and_feel('Topanga') layout = [...
  24. 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...
  25. antoniacarol

    How can I fix a ValueError when trying to terminate a while loop in Python?

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

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

    Same file name, Different Files (Different Content) Python 2.7 Jupyt

    So I have Python 2.7 ( Don't ask) installed in my VM. Now I have two files named " Untitled 10" in my Jupyter notebook therein ( Notice the bottom cell in both files , named "Untitled 10" -- please see top of attachments -- which have different content in the "bottom-most" cell ); please...
  28. cobalt124

    Easy Guide for Installing Pillow and Pygame on Windows XP with Python 3.4.3

    I'm using Windows XP without Internet access with Python 3.4.3 installed. I wish to install Pillow and Pygame, but can't get them to install correctly. I'm going round in circles on the Internet, StackExchange and other sites. I've tried using: Pillow-5.4.1.win32-py3.4.exe...
  29. W

    Python 2.7 Pandas BSoup4 Scrape: Outputs Column Names but not the Data

    Hi, trying to scrape a page : https://www.hofstede-insights.com/wp-json/v1/country I get the list of columns I want, but not the data assigned to the columns in the page that is being scraped. from bs4 import BeautifulSoup import pandas as pd import requests url =...
  30. W

    Figuring out "Definition" in Python 2.7 Anaconda Birthday Dictionary

    --- Say we have the dictionary in Anaconda 2.7 Jupyter :--- B={'A1':'Jan1' , 'A2':'Feb2',...} of Birthdates. ---I can call a name , e.g., 'A1' , using Birth[name]. As in :--- print('What is your name '\? ') name=input() print('Yes, Birth[name] is in our list') ---How do I call a Date? I want...
  31. K

    How can I multiply elements in nested lists in Python and print the new list?

    I have a list containing several lists with two elements each. I want to multiply the last element in the inner lists with a number x, and then print the new list. How do I do this?
  32. S

    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())
  33. F

    Is Turtle a Module or Library in Python?

    Hello, I am trying to fully understand the difference between module, library, and package in Python. I think a module is a single file with a specific functionality. A library is like a directory: it contains multiple files, i.e. multiple modules. A package contains multiple libraries and...
  34. F

    Installing OpenCV using Python

    Hello Everyone, I am trying to install OpenCV, which is a library for image processing. I am downloading the Python Anaconda distribution where to use OpenCV. I read that the following commands are needed at the prompt: conda install -c conda-forge opencv install means install the library...
  35. 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...
  36. Wrichik Basu

    Python 3.7.4 lacks a proper linspace function?

    Basically, I wanted to create a Numpy array with linearly spaced integers between 0 and 3, the increment being 0.01. Yes, I know Numpy offers a linspace function. I used it like this: x = np.linspace(0, 3, num=300) (where np is numpy), and got this: I know that the numbers cannot be exact...
  37. W

    Any Experience with SQL Server Dev + Python& ML Server?

    Hi all, Curious if anyone has worked with SQL Server Dev 2017 with ML and Python Server, i.e., with the full data analysis platform and what your experiences are.
  38. Vick

    Coding Riemann (0,4) Equation in Python - Help Needed!

    Hi, I've coded Riemann tensor in python successfully. However, I recently stumbled onto another Riemann equation for the valence (0,4) as shown in the following link: Riemann (0,4) I'm having troubled coding the last part after the partial derivatives and the plus sign. Can anyone help me? Thanks
  39. B

    Problem in a simulation with Python

    I wanted to simulate the Ising model and it was okay until I wanted to get the fluctuations <M^2>. In fact, first, I wanted to obtain the magnetization M : $$ M = \sum_i \sigma ^ z_i $$ and it worked, I got indeed the magnetization M by writing these lines : sigmaxop = [] sites = []...
  40. D

    Exploring ALMA Image Data with Viridis Colormap

    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()
  41. 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...
  42. Arman777

    Python equation solver, I'm getting a floating point error

    I am trying to solve the equation like this, from sympy.solvers import solve from sympy import Symbol import math x = Symbol('x') A, B, C, D = 0.59912051, 0.64030348, 263.33721367, 387.92069617 print(solve((A * x) + (B * math.sqrt(x**3)) - (C * math.exp(-x / 50)) - D, x , numerical = True))...
  43. T

    Flow Chart For a 'for' Loop In Python

    I am currently learning python and to understand the my code fully and to make notes I am trying to draw flow charts to compliment my code. My issue is I am not sure what to put in the flow charts or really how to represent them as clearly as possible. I have done a google search but I am bit...
  44. W

    Using different IDEs (Anaconda, IDLE) for Python 2.7, 3.5 Respectively

    Hi, I would like to be able to use both IDLE and Anaconda Navigator/Jupyter IDEs for Python 3.7 (64-bit), 2.7 respectfully. I can open up and work with IDLE. I understand Python 2.x is for legacy systems mostly but I spent a lot of time using data analysis packages in/with Anaconda for 2.7 and...
  45. N

    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 =...
  46. 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...
  47. Avatrin

    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?
  48. 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...
  49. m4r35n357

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

    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...
Back
Top