Python Definition and 662 Threads

  1. Amathproblem22

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

    Python 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...
  3. 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...
  4. PeroK

    Python 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...
  5. W

    Python 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...
  6. 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...
  7. Eclair_de_XII

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

    Java 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...
  9. S

    Python 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...
  10. M

    Python 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...
  11. patric44

    Python 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...
  12. V

    Python 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...
  13. V

    Python 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...
  14. 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...
  15. V

    Python 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...
  16. Avatrin

    Python 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?
  17. S

    Python 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 =...
  18. Jozefina Gramatikova

    Python How to Visualize a Matrix with Non-Numeric Values 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...
  19. S

    Python 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>
  20. 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)...
  21. V

    Python 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...
  22. 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...
  23. R

    Python 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...
  24. V

    Python 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...
  25. gmax137

    Python RIP Python Terry Jones: Remembering A Legend

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

    Python 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...
  27. B

    Python 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...
  28. N

    Python 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 = []...
  29. W

    Python 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 =...
  30. Arman777

    Python 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 = [...
  31. L

    Python 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...
  32. antoniacarol

    Python 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...
  33. 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...
  34. W

    Python 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...
  35. cobalt124

    Python 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...
  36. W

    Python 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 =...
  37. W

    Python 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...
  38. K

    Python 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?
  39. S

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

    Python 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...
  41. F

    What Does the -c Flag Do in conda install?

    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...
  42. 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...
  43. Wrichik Basu

    Python 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...
  44. W

    Python 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.
  45. M

    Python 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
  46. B

    Python 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 = []...
  47. 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()
  48. JayZ0198

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

    Python 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))...
  50. T

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