Python Definition and 655 Threads
-
Python Solving Linear Programming problems in python PulP
Okay so far I have come up with the following: The objective function is: 30LADA + 40LAHO + 50SADA + 40SAHO + 110DANY + 125DACH + 105HONY + 115HOCH (to read this please see the table above as I have just used the first two letters of each except NY which I have represented by NY). In these I...- alpha
- Thread
- Linear Linear programming Programming Python
- Replies: 1
- Forum: Programming and Computer Science
-
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 =...- btb4198
- Thread
- Conditional Python Translation
- Replies: 3
- Forum: Programming and Computer Science
-
Python Are Python strings truly immutable?
I am using "Introducing Python" (Lubanovic) to teach myself Python. I read that Python strings are immutable, then I see code like this - string1 = 'base_val' string1= 'new_val' not throw up an error. A little investigation shows me that the interpreter created two strings and string1 is a...- Grinkle
- Thread
- Python Strings
- Replies: 10
- Forum: Programming and Computer Science
-
M
Python Does this python script match the math?
Hi PF! I've posted a bunch lately and you have been SO helpful (seriously, thank you all). Can you corroborate if my python script below matches the math? I'd seriously appreciate it! The math: $$\max_{x\in [0.7,1)}F(x) : F(x) := \sum_{t = 250}^{750} \log\left( P_{\nu=3} \left(...- member 428835
- Thread
- Match Python
- Replies: 15
- Forum: Programming and Computer Science
-
I Calculate Gaussian Curvature from 4D Metric Tensor
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...- Sciencemaster
- Thread
- Curvature Curvature of spacetime Gaussian Mathematica Metric Metric tensor Program Python
- Replies: 14
- Forum: Special and General Relativity
-
M
MATLAB Can I run sections of code independently in Python and C++ like in MATLAB?
Hi PF! I typically code in MATLAB. Here, if I run the following program %% Section 1 x = 5; y = 2; %% Section 2 z = x + y; everything works. But now let's say I wanted to change line 5 to z = x - y. In MATLAB this is simple: I can simply change line 5 and rerun section 2. Is there a way to...- member 428835
- Thread
- C++ Matlab Python
- Replies: 5
- Forum: MATLAB, Maple, Mathematica, LaTeX
-
M
Should users confirm their account deletion before it is processed?
Hey! 😊 I have written a code in Python for a server to search for movies. At the site for the user I have added at the html template the options to change the password and to delete the account. For this do I have to write a separate html or a separate endpoint for these ones or can I write...- mathmari
- Thread
- Html Python
- Replies: 24
- Forum: Programming and Computer Science
-
Python 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...- TheJP78
- Thread
- Building Python Simulation Solar Solar system System
- Replies: 2
- Forum: Programming and Computer Science
-
M
Python One-line Python Code that returns a sequence of integers
Hey! 😊 I want to write a one-line Python generator or iterator expression that returns the sequence of integers generated by repeatedly adding the ascii values of each letter in the word “Close” to itself. The first 10 integers in this sequence are: 67, 175, 286, 401, 502, 569, 677, 788, 903...- mathmari
- Thread
- Code Integers Python Sequence
- Replies: 4
- Forum: Programming and Computer Science
-
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...- Graham87
- Thread
- Earth Numerical Numerical methods Orbit Python
- Replies: 3
- Forum: Engineering and Comp Sci Homework Help
-
Comp Sci Orbit of Earth: Plotting Trajectory
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 =...- Graham87
- Thread
- Earth Numerical methods Orbit Python
- Replies: 6
- Forum: Engineering and Comp Sci Homework Help
-
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?- Swamp Thing
- Thread
- Method Python
- Replies: 6
- Forum: Programming and Computer Science
-
M
HTML/CSS Python - HTML : Isn't this a dictionary ?
Hey! 😊 I have written a program in Python where API calls to the server to get currency exchanges. Now I want to add a part for the user, i.e. with html. The endpoint is : @route_rates.route("/all/") def get_all(): return render_template("currency.html", my_currency =...- mathmari
- Thread
- Html Python
- Replies: 2
- Forum: Programming and Computer Science
-
M
Python Python - Endpoint : Can the function not return an array of dictionaries ?
Hey! 😊 I am trying to write a code for a server in Python and I got stuck. I gave as an input a csv file and using pandas we get a dictionary where the titles are the keys and the inputs are the values. From that we get the below : I have written the below endpoint to get all the...- mathmari
- Thread
- Array Function Python
- Replies: 3
- Forum: Programming and Computer Science
-
M
Python 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...- Master1022
- Thread
- Program Python
- Replies: 2
- Forum: Programming and Computer Science
-
Python Algorithmic trading with python
If you have used an online course pertaining to the title, could you write a short review? Not looking for a book.- ergospherical
- Thread
- Python
- Replies: 1
- Forum: Programming and Computer Science
-
M
Python Import python list from .txt file into Mathematica
Hi PF! I am trying to import k.txt file into Mathematica as a list of numbers. The k.txt looks like this: [5.315967917338153e-06, -3.204321972222162e-08, 3.6041782425371564e-09, -3.853442465663655e-08, 8.699510604529962e-07, -1.4284341965847237e-08, 2.855341882658808e-09...- member 428835
- Thread
- File List Mathematica Python
- Replies: 5
- Forum: Programming and Computer Science
-
C/C++ 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...- user366312
- Thread
- C++ Code Monte carlo simulation Polymer Python Simulation Simulations Source
- Replies: 1
- Forum: Programming and Computer Science
-
F
Python Python "ImportError: bad magic number ...."
# Test suite for Problem Set 3 (Simulating Robots) # Fall 2016 import sys import threading import traceback import unittest import random import imp test = imp.load_compiled("test", "test.pyc") import ps3 def xyrange(x_upper_bound, y_upper_bound): """ Returns the cartesian product of...- fishturtle1
- Thread
- Magic Python
- Replies: 1
- Forum: Programming and Computer Science
-
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...- bikashdaga
- Thread
- Method Python Static Variable
- Replies: 3
- Forum: Programming and Computer Science
-
R
Python 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...- rgtr
- Thread
- flask Python
- Replies: 13
- Forum: Programming and Computer Science
-
M
Python Use Python to integrate a function constructed in Mathematica
Hi PF! I followed someone's help on here and have the following code in python that performs monte carlo integration from math import * from random import * def integrate(alpha): # MONTE CARLO INTEGRATION OVER NON-RECTANGULAR DOMAINS def f(pt): # RETURN INTEGRAND AS FUNCTION...- member 428835
- Thread
- Function Integrate Mathematica Python
- Replies: 5
- Forum: Programming and Computer Science
-
R
Python TemplateSyntaxError in Python Flask
This is in python flask. I am getting an error line 16, in template <h2> <a href="{{ url_for('userinfo.profile', username=current_user.username, 'update_profile') }}"> update_profile_info </a> </h2> jinja2.exceptions.TemplateSyntaxError: invalid syntax for function call expression The...- rgtr
- Thread
- flask Python
- Replies: 9
- Forum: Programming and Computer Science
-
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...- akerkarprashant
- Thread
- Comparison Image Image processing Python Software
- Replies: 17
- Forum: Computing and Technology
-
M
Python Why Does My Python Code Output None Instead of the Next Permutation?
Hi PF! I'm trying to write a code that, given a list of integers, will output the next lexicographic permutation. But my output gives me None, and I can't see why. Is it because I am incorrectly calling the reverse function? Any help is greatly appreciated! class Solution(object): def...- member 428835
- Thread
- Code Python
- Replies: 34
- Forum: Programming and Computer Science
-
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)...- BRN
- Thread
- Error Input Network Neural Neural networks Python
- Replies: 2
- Forum: Programming and Computer Science
-
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...- bolzano95
- Thread
- Classes Programming Python
- Replies: 19
- Forum: STEM Academic Advising
-
M
Python Python header question from leetcode solution
Hi PF! I am looking at the following code class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def removeNthFromEnd(head: ListNode, n: int) -> ListNode: # Two pointers - fast and slow slow = head fast = head # Move fast...- member 428835
- Thread
- Python
- Replies: 9
- Forum: Programming and Computer Science
-
M
Python Executing Specific Python Lines in VS Code on Ubuntu
Hi PF! I am running VS Code for python on Ubuntu. Is there a way to execute a specific python line? As I currently have it set up, on the terminal input at the bottom of the screen, I can only work through the terminal, so a command like print('hello world') won't do anything. THanks so mcuh!- member 428835
- Thread
- Code Python Visual
- Replies: 2
- Forum: Programming and Computer Science
-
M
Python Why is spaces equal to tree_height-1 in the Christmas tree code in Python?
Hey! :giggle: I found online the following code for a christmas tree in Python : tree_height = input("Enter the tree height : ") tree_height = int(tree_height) spaces = tree_height-1 hashes = 1 stump_spaces = tree_height-1 while tree_height != 0 : for i in range(spaces)...- mathmari
- Thread
- Code Explanation Python
- Replies: 5
- Forum: Programming and Computer Science
-
I
Python Looking for programming exercises for OOP in Python
Hello I learned object oriented programming in Python from a book. But it does not have any programming exercises. I do not learn very much unless I do some programming exercises. It helps to hone the skills. So, I am looking for some exercises if OOP Python is taught in universities. Usually...- issacnewton
- Thread
- Exercises Oop Programming Python
- Replies: 3
- Forum: Programming and Computer Science
-
Python I'm not able to write a script that reduces a matrix to RREF in Python
Summary:: I'm not asking for help, but I'm asking for an opinion. Is this a sign that I probably should not be pursuing a career in software development or computer science? I basically feel like this in general wrt any subject I am studying, really, whenever I feel stumped on a given problem...- Eclair_de_XII
- Thread
- Matrix Python
- Replies: 12
- Forum: Programming and Computer Science
-
M
How can we define the __mult__ method to return a Complex object?
Hey! 😊 Construct a class named Vector that expresses the meaning of the vector of numbers. The initialization function, __init__ will take as a argument a tuple corresponding to the vector. This tuple will be stored in the variable named coord. Also, __init__ will calculate the Euclidean...- mathmari
- Thread
- Class Python Vector
- Replies: 13
- Forum: Programming and Computer Science
-
M
How do we properly set and get instance variables in a class?
Hey! :giggle: Construct a class named Student which when initializing its objects has the following variables : - first_name (string) - last_name (string) - email (string) The class should also support the following functions implemented as functions (methods): - set_id_number: set a...- mathmari
- Thread
- Class Python
- Replies: 9
- Forum: Programming and Computer Science
-
Python I need to make an application that uses database in python
I need to make an application that uses database in python, what should I make? Firstly I need to tell about me. I know 0 about programming. I have learned basics of python only. What are the apps that use database that are upto my level of programming? I am planning to use django...- shivajikobardan
- Thread
- Application Database Python
- Replies: 17
- Forum: Programming and Computer Science
-
Python Python - Confused in list comprehension
I want to find difference between two list. I came across sth called list comprehension. I can't tell you how confused I am with this. # Python 3 code to demonstrate # to remove elements present in other list # using list comprehension # initializing list1 list1 = [1, 3, 4, 6, 7] #...- shivajikobardan
- Thread
- Confused List Python
- Replies: 4
- Forum: Programming and Computer Science
-
Python Find next perfect square -- Not working in python
def find_next_square(sq): # Return the next square if sq is a square, -1 otherwise sq2=(sq**1/2) xyz=isinstance(sq2, int) if (xyz==True): print("Is perfect square") nextsq=sq+1 print("Next perfect square=",nextsq**2) else: print("Not...- shivajikobardan
- Thread
- Python Square
- Replies: 18
- Forum: Programming and Computer Science
-
Python Find next perfect square not working in python
def find_next_square(sq): # Return the next square if sq is a square, -1 otherwise sq2=(sq**1/2) xyz=isinstance(sq2, int) if (xyz==True): print("Is perfect square") nextsq=sq+1 print("Next perfect square=",nextsq**2) else: print("Not perfect...- shivajikobardan
- Thread
- Python Square
- Replies: 10
- Forum: Programming and Computer Science
-
Python Nested for loop in python, understanding with dry run?
Here is the code that I am talking about-: n=int(input("Enter a number")) for num in range(2,n+1): for i in range(2,num): if(num%i==0): break else: print(num,end="") If I give n=5 output should be 2,3,5. Here is my dry run. Everything is fine except for 2...- shivajikobardan
- Thread
- Loop Python
- Replies: 6
- Forum: Programming and Computer Science
-
Python How to check whether a string is odd palindrome in python?
I am learning to code and 1 thing that surprises me is how do I internalize all the code? I understand the code. I know the algorithm as well. But I want to be able to solve any types of problems(related ones) after learning 1 code. How do I become able to do that? So for that I am first trying...- shivajikobardan
- Thread
- Python String
- Replies: 3
- Forum: Programming and Computer Science
-
Python How to check a string is odd palindrome in python?
I am learning to code and 1 thing that surprises me is how do I internalize all the code? I understand the code. I know the algorithm as well. But I want to be able to solve any types of problems(related ones) after learning 1 code. How do I become able to do that? So for that I am first trying...- shivajikobardan
- Thread
- Python String
- Replies: 2
- Forum: Programming and Computer Science
-
F
Python Explore Alan Turing's Computable Numbers & Generate Pi with Python
I found this article about Alan Turing and his concept of Turing machines on the AMS website. Since we often get questions about countability and computability I thought it is worth sharing. https://blogs.ams.org/featurecolumn/2021/12/01/alan-turing-computable-numbers/ It also contains a Python...- fresh_42
- Thread
- Computable Countability Numbers Pi Python Turing
- Replies: 1
- Forum: Programming and Computer Science
-
C
Comp Sci Validating Braces Placement for Expression Evaluation
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...- CGandC
- Thread
- Dynamic programming Expression Permutation Placement Python Recursion String
- Replies: 10
- Forum: Engineering and Comp Sci Homework Help
-
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...- SamRoss
- Thread
- Code Green Latex Python Visual
- Replies: 15
- Forum: Computing and Technology
-
Python How do for loops work in python?
str1="hello" for stringElement in str1: print("str1","=",stringElement) Strings are arrays in python and they are represented like this. Now I want to understand how the for loop is working here. My dry run-: for h in str1 print h for e in str1 print e and so on till...- shivajikobardan
- Thread
- For loops Loops Python Work
- Replies: 5
- Forum: Programming and Computer Science
-
Python Error occurred in pycharm python IDE
# # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd51d4257f, pid=9852, tid=11684 # # JRE version: OpenJDK Runtime Environment JBR-11.0.12.7-1504.40-jcef (11.0.12+7) (build 11.0.12+7-b1504.40) # Java VM: OpenJDK 64-Bit...- shivajikobardan
- Thread
- Error Python
- Replies: 2
- Forum: Programming and Computer Science
-
Python Confused in name binding in python
(I Didn't use code formatting here as I felt it was not necessary) I have read multiple textbooks, articles and watched multiple videos about name binding in python. Till now what I understand can be summarized in this-: x=1 means name x is binded to object "1" z=x and we know x=1 => z=1 so...- shivajikobardan
- Thread
- Confused Python
- Replies: 1
- Forum: Programming and Computer Science
-
Python Confused about name binding in python
(I Didn't use code formatting here as I felt it was not necessary) I have read multiple textbooks, articles and watched multiple videos about name binding in python. Till now what I understand can be summarized in this-: x=1 means name x is binded to object "1" z=x and we know x=1 => z=1 so...- shivajikobardan
- Thread
- Confused Python
- Replies: 1
- Forum: Programming and Computer Science
-
Python Best book to keep as reference for python?
1) Basic python only no data science or machine learning or game development. 2) I have CS experience and some programming experience but I am really bad programmer, so you can discount my programming experience. But I can learn cs concepts on the go. 3) Contains lots of solved and unsolved...- shivajikobardan
- Thread
- Book Python Reference
- Replies: 7
- Forum: Programming and Computer Science
-
Python What is the best interpereter/IDE for python basic programming?
What is the best IDE out there? It should be easy to use. Not as easy as online editors though.- shivajikobardan
- Thread
- Programming Python
- Replies: 18
- Forum: Programming and Computer Science