Python Definition and 662 Threads

  1. M

    Python How to calculate rows where it has values in at least 3 columns

    I am trying to count number of rows that has values in at least 3 columns so the output based on the image shared should be 4. I tried using the code below but it is resulting in the same shape as the whole table which is 7. counts = df[(df[['a', 'b', 'c', 'd]] != 'no_label').count(axis=1) >= 3]
  2. M

    Python Python not recognizing MAX value in a list

    i have a value that is generated as the max value for example from this list [0.6000001, 0.3, 0.3, 0.4] clearly the maximum value is 0.6000001 but python does not seem to be able to recognize this value as the maximum. i have tried so many ways to solve it but to no avail. even when changing...
  3. M

    Python How to check that none of the values are equal?

    the code below intends to take the maximum value that is calculated for each of the variable but after the max value is obtained I am not sure how to ensure there are no 2 or more values are the same in the if else loop as if 'a' has the max value of 3 and 'b' also has the max value of 3 then...
  4. M

    Python Problem with appending a dataframe after a loop

    I am iterating over 2 variables below and after the calculation are done, i'd like to append the dataframe to add the rows after each iteration, but what is happening now is that the row is getting replaced instead of getting added. pre = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] post = [0, 1, 2, 3, 4...
  5. M

    Python How to compute the percentage of values based on multiple columns

    I have a dataframe as shown in the picture and what I am trying to do is to calculate the number of occurrences based on the values in 2 columns and then calculate the percentage of the occurrences. I have tried the following code but it gives me a zero value in the end and i don't know why...
  6. M

    Python How to create a Multi-index dataframe

    I would like to generate a multi index dataframe that looks like the image attached. how do i do this in python? I tried this approach but it doesn't give me the output as expected: https://stackoverflow.com/questions/28289440/creating-an-empty-multiindex
  7. M

    Python How to convert tuple values to strings?

    i have a column in a dataframe that contains values in the form or tuples (example: ('A',) ) and I want to convert these values to string format so that ('A',) becomes 'A' How do I do this in python for a dataframe? Thanks.
  8. M

    How to compute distance of points to a line?

    I have computed a line from point A to point B by just subtracting the coordinates as below: line = np.array (x2-x1, y2-y1) I am not sure if I need to form the formula for this line first by computing the slope and intercept but I continued my code as below, slope being m and b being the...
  9. M

    Python How to correctly append a Dataframe?

    I have code snippet as below and when i run it, the dataframe seems to append after every loop and does not add the previous row into the frame, so at each time only one row is populated into the new dataframe. How do I ensure that the append function adds the previous row as well...
  10. M

    MATLAB Switched from win10 and MATLAB to ubuntu and python"q"

    Hi, I felt like I have to learn more than one coding language, and wanted to strengthen my coding skills in general. I am good with Relap5 but I want to learn OpenFoam. is what I did logical and going to be worth the pain ? also I only have the Relap5 version of a windows ,is it possible to run...
  11. A

    Python How to solve this electrostatic potential integral equation with Python

    Hi! I would like solve this kind of relation: \phi = \int_0^r \phi (r') 4 \pi r'dr' But I don't know how to proceed... Can you advise me ? Thank's in advance !
  12. E

    Python Numerical Integration in Python

    I want to find the numerical solution to the following nested integral in Python \frac{K!}{(K-M)!}\int_{x_1=0}^{y}\int_{x_{2}=x_1}^{\max(x_1,\,y-x_1)}\cdots \int_{x_M=x_{M-1}}^{\max(x_{M-1},\,y-\sum_{m=1}^{M-1}x_m)} \frac{1}{(1+x_M)^{K-M+2}}\prod_{m=1}^{M-1}...
  13. S

    Dealing with 1000 digit numbers

    Hi, Mostly i work with Octave / Matlab but i am trying to get into python also. Lately i have a couple problems where my numbers can't be represented in binary64 or float64 default format because they exceed the max of 1.8x10^308. Is there a common way people deal with this (without toolkits)...
  14. J

    Python Python programming on Pythonanywhere

    Hi all; I've already posted to P_Anywhere's site but... I'm trying to run a script that needs a data file piped to it. Now P_ Anywhere gives you a resident directory and mine contains the program and the data file. Sooo... bonds.py ethane.xyz maybe? Nah. Doesn't like that. But! I did get it to...
  15. N

    Python Unitary transformation using Python

    I would like to ask about unitary transformation. UA(IV) UB*UA(IV) UAT(UB*UA(IV))=UB(IV) UB(IV)*(X) IVT(UB(IV)*(X))=UB(X) UBT*UB(X)=X From the information above, UAT,IVT and UBT are the transpose of the complex conjugate. The aim of this code is to get the value of X in the step 4. This is...
  16. Arman777

    Python Why Python IDLE is faster than Spyder or Jupyter notebook

    I defined a simple prime function and then I append each number to an array up to 1 million and then later 2 million. In both cases, Python IDLE gives me the answer in 4 and 9 seconds respectively, but Spyder and Jupyter Notebook gave me in 12 and 24 seconds. I wonder why this happened. The time...
  17. I

    Why doesn't SNEC work with my profile?

    Hello, I have made a python script that splits my desired star.data file from a MESA model into two distinct files that I need to use in SNEC link here: https://github.com/abostroem/SNEC My script is here : https://github.com/ilaur/SNEC-Split When I try to run SNEC with my custom profile it...
  18. Avatrin

    Learning back-end development with Flask

    Hi I want to learn and understand web development, and just knowing what to do is not enough for me; I, to the extent it is possible, want to know how the web works. So, if I develop a web app or website with Flask, I want to know what is going on under the hood (it's just how my head works...
  19. Arman777

    Python Recommended Python Books for Beginner Programmers

    Hey all, I think most of you know me and probably this question will sound silly but anyways, I am learning python over a 3 month now and The course in the school is over and there will no other course. I want to learn more and is there any source you can recommend me. What I know: 1-I know...
  20. R

    How Can a Mathematics Major Like Reid Benefit from Joining a Science Forum?

    Hello members of PF, my name is Reid Honeycutt. I am a mathematics major at American River College, Sacramento. My mathematical interests are primarily in the areas of algebra and logic. I also love physics and materials science, economics, and programming in python. My motivation in joining...
  21. M

    Coding a numerical approximation for a damped pendulum

    Hi there. I have a question about the damped pendulum. I am working on an exercise where I have already numerically approximated the solution for a simple pendulum without dampening. Now, the excercise says that I can simply change the code of this simple situation to describe a pendulum with...
  22. J

    Python How can numpy.dot() be used in Python to solve Markov chain Monte Carlo methods?

    Homework Statement I'm taking an online course in Stat. Mech. and we're working on Markov chain Monte Carlo methods. One of the programs supplied uses the following: Mentor note: Added code tags import numpy neighbor = [[1, 3, 0, 0], [2, 4, 0, 1], [2, 5, 1, 2], [4, 6, 3, 0], [5...
  23. Avatrin

    Python How can I create vector images with Python for laser cutting?

    Hi I wish to use Python to create art which can be exported as dxf files for use with laser cutters.While Processing is available for Python, it only creates raster images. What are my options if I want to create vector images? This may be the wrong forum for this question... If it is, where...
  24. MatthijsRog

    I How Can I Accurately Fit an Airy Distribution Over Noisy Resonance Data?

    Hi all, I performed a resonance experiment over the past two weeks, in which I collected the intensity of a Fabry-Perot cavity whilst adjusting the mirror distance with a piezo-element (the specific setup of the experiment is fairly detached from the question I will ask). My raw data is...
  25. G

    Python Practicing Python and R at the same time

    Hello, I've learned some of the basics of python through the sololearn Python 3 course (I also started the first week of the MIT Intro to computer science and programming on edx.org, but I found it beyond beginner level and decided to go through the sololearn Python 3 first). My company...
  26. A

    New member and enthusiast to share my experience and learn

    hello all i am a new member on Physics Forum i am a last year master student in fundamental physics ( again ) and also have done a master in condense mater and nano-science i worked on noble solid /amorphous interface in my first master internship ( DFT and ab initio molecular dynamic using...
  27. CrosisBH

    Python Why Does My VPython Moon Orbit Simulation Not Maintain a Circular Path?

    Code: https://pastebin.com/5LajNBpj So I was messing with VPython, trying to create an Earth-Moon System. I got the actual gravity to work, and can create some nice ellipical orbits. However I run into trouble trying to make the actual (almost) circular orbit of the moon. I know that the...
  28. A

    Python Create a sign-out sheet in Python

    Hello everyone, I am trying to create a sign out sheet as if I am a teacher and its so then people can sign out electronically. I know very little python and I have googled most things. I have never worked with a text file before. I am trying to make so it will ask my name, destination, and time...
  29. Nikhil N

    MATLAB How can I run Python by getting values from Matlab

    I have a python script for which the input data are coming from Matlab. I have tried to use pymatlab, but it is failing. Can anyone suggest any other method?
  30. C

    Python Polynomial expansion from Python to Mathematica

    Hi everybody. In Python there is a library called chaospy. One useful command is cp.orth_ttr which generates a polynomial expansion, e. g. a series of orthogonal polynomials or orders zero, one, two... for a random variable e.g normal, uniform... For more information see...
  31. scottdave

    Python Interesting article how to use Pandas with Excel sheets

    I came across this article about using Pandas in Python to read in a multi-tab spreadsheet to Python, and work with the data then write back to an Excel spreadsheet...
  32. C

    Python Weights and interpolation -- Replicating Python code with hand calculations

    Hello everyone. I have a Python code which calculates, given a continuos uniform random variable U(-1,1), the order of a interpolation polynomial and a set of points the evolution of a function of this random variable. i.e. v0 = cp.Uniform(-1,1) t = np.linspace(0, 10, 10) order=1 . . . plt.plot...
  33. C

    Python How do I fix this galactic source analysis using python?

    Homework Statement This is related to Astronomy & python . I am trying free-up sources on TS map on a galactic source with python script. But when I run the script, at the end of the process, I get the following run time error. Traceback (most recent call last): File "find_new_sources.py"...
  34. M

    Numerically find the energy of the delta-well's bound state

    I'm working on an assignment where I'm required to numerically find the energy of a delta-potential's bound state. To do this, we've converted the time-independent schrödinger equation to an eigenvalue problem with E the eigen value, ψ the eigen vector and H a matrix as follows: with ##t =...
  35. S

    Python Help with POPPY (Physical Optics Propagation in PYthon)

    If someone has used the python program POPPY, I'd like some help. How can I set up two wavefronts entering at slightly different angles, and then see the interference pattern?
  36. S

    Python Porting Python Code to Fortran for Parallel Computing

    I have a simulation that involves a lot of dense linear algebra with a lot of complex arrays, that was written in python's numpy and then sped up with cython. Unfortunately I'm stuck with python's GIL (global interpreter lock), which prevents the use of numpy with multi-threaded code. I'm...
  37. Hi Im Paul

    Python What's wrong with my bisection method code?

    Hello, I am assigned to write a code using bisection method (aka binary search method) The equation is 10sin(x) - x^3 - N where N = 1,2,3,4,5,6,7 My code is from math import sin def neg(a, b): return a*b> 0 def bisectx(funcx, lowx, highx,n): assert not neg(funcx(lowx,n), funcx(highx,n))...
  38. C

    MATLAB Help: Convert Matlab to Python code

    I'm working on a convolutional neural network project that classifies histopathological images of breast tumors. All my code is in python. Part of the image preprocessing involves appearance normalisation to account for the variation in histological staining. The only code for the preprocessing...
  39. E

    Python Understand Binning Data in Python

    Hello, I was reading an example on binning data, where a continuous variable is transformed into a categorical variable. The dataframe name is df, and the continuous variable's column's name is 'horsepower'. We would like to transform the continuous variable feature into a categorical feature...
  40. E

    Python Good books to learn machine learning using Python

    Hello, I am new to both Python and machine learning. I am trying to learn by reading books on machine learning using Python. I started with this book. I could manage the first 3 chapters (although I had to dissect the codes on Github because not all the codes are included and explained in the...
  41. D

    How do I save a file in Sublime to a specific folder?

    Hi guys. Just wanted to see if I could get a point on this problem I'm having. I'm using a book to learn Python3 and I'm using SublimeText as an editor. The book initially told me to configure Sublime for Python3 by typing this into a blank Sublime file: { "cmd": ["/usr/local/bin/python3"...
  42. Demystifier

    Python What does this Python program do?

    Can someone tell me what does this Python program do? :wink: s = 's = %r\nprint(s%%s)' print(s%s) Mentor: add html code tags
  43. Morbidly_Green

    Python Removing previously plotted points on scatter plot; python

    Homework Statement I'm plotting moving particles and I need a way to refresh the graph space with every loop. Meaning I want the points to NOT leave a trail of other points behind them . Basically I want to get rid of the old points as I plot new ones. Homework Equations N\A The Attempt at a...
  44. M

    Python Why Isn't QPushButton Triggering Method in PyQt5?

    I'm new to this forum, as well as Python, so bare with me, won't you:) Ok, so I have this GUI written in python and utilizing PYQT5. I have a functioning version, but I now want to add a QpushButton that executes a method called add_Bladebox. This method adds a doublespinbox to the gui. The...
  45. X

    How to Calculate Correlation Time Using Numpy for Monte Carlo Simulations?

    I'm creating a Monte Carlo simulation of the 2D Ising Model for a graduate course in computational materials science. Part of the assignment is to calculate the uncertainty in the calculation of the average magnetization per spin. To do so, we are told to find the correlation time for our data...
  46. J

    Python How can I integrate sinusoids in python code using FFT?

    Hello, Thank you for taking time to read my post. I have a discrete set of data points that represent an acceleration signal. I want to take the integral of this set of points twice so as to get a function which represents the position over time. To accomplish this, I have taken the FFT of the...
  47. S

    Python Discrete Fourier Transform in Python

    Homework Statement I need to calculate the derivative of a function using discrete Fourier transform (DFT). Below is a simplified version of my code (just for sin function) in python Homework Equations from __future__ import division import numpy as np from pylab import * pi = np.pi def...
  48. K_Physics

    Python User-Defined Function in Python

    Homework Statement So currently I'm working with user-defined functions. Initially, the code inside the user-defined function worked but when I attempted to change it into a user-defined function, it produces incorrect values. Homework Equations No need for any equations The Attempt at a...
  49. Avatrin

    Python Working with PNG images in Python

    Hi I have to run a few algorithms using Python on PNG-images. However, I also know that PNG is compressed... How do I do this? I need to learn the following: 1: Extracting the RGB information about the pixels. 2: Isolating parts of the image (for example, importing an image and only working on...
  50. Avatrin

    Python How to Import and Manipulate Data from a Text File in Python?

    Hi Lets say I have a txt file with m rows with n columns of numbers of the form: Lets say I want to take every p'th row and take the second and third columns and turn it into a \frac{m}{p}\times 2 matrix. How would I go about doing that?
Back
Top