How can I compute this?
Suppose I have the following numpy array:import numpy as npmy_data = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]])# obtain the lengthn = len(my_data) # 5I want to do this...
View ArticleFileNotFoundError: [WinError 2] The system cannot find the file specified:...
Trying to delete all but one file in a given directory. Looked at other related posts but my question seems specific to getting names from os.listdir and needing full path with extensions to use...
View ArticleCan't run python program
Id be very happy to know how to run the program? i've been given this command:python3 calculator.pyI tried putting this text :# Prompt for user inputa = float(int(input("Enter the first number: 1")))b...
View ArticleWhen I try to run a new script via another script, the current script reruns
When I try to run a second script from a first script, the first script reruns from the beginning. Below is the code where i try to run the new script. I don't know where the problem lies.def...
View ArticleWhy are these two datetimes not equal?
from datetime import datetime, timedeltafrom zoneinfo import ZoneInfochi = ZoneInfo("America/Chicago")nyc = ZoneInfo("America/New_York")dt1 = datetime(2024, 3, 10, 3, 30, tzinfo=chi)dt2 =...
View ArticleWhy does the function always return 0? (function + tkinter + global...
Here is a fragment of my code:from tkinter import*root = Tk()root.title("Example")root.geometry("1000x250")root['bg']="black"def ask2(question,var1,var2): ans = 0 def button1(): global ans...
View ArticleHow do I get the full number? [duplicate]
I am extremely new to python, and I have been trying to wrap my head on what I need to do here. I'm trying to write some code where I do the following:Open a fileCreate a loop where I read through the...
View ArticleHow to use threads function in my results?
I'm attempting to introduce diversity into my result values, yet I encounter challenges as they consistently yield NA values or remain constant across all sentences. This presents an issue in achieving...
View Articlecs50p little professor question, my code get rejected because of wrong level...
this is my code for the little professor problem , the task is when the level is not 1 ,2 or 3 repromt , this is what the code does but still get reject for the level repromt:) professor.py exists:(...
View ArticleImport Custom Python Modules on EMR Serverless through Spark Configuration
I created a spark_ready.py module that hosts multiple classes that I want to use as a template. I've seen in multiple configurations online that using the "spark.submit.pyFiles" will allow you to...
View ArticlePandas Apply running slow
I am calculating weighted average post outlier removal in pandas.When I am going to like 1M rows, I am seeing significant time taken in filter_and_compute method. Why is that? What can be done better?...
View ArticleUsing 'append' method on nested lists gives syntax error [closed]
given a set of letter combinations (aa,ab)and a set of numbers (1,2,3)I want to generate:(aa1,ab2) (aa1,ab3)(aa2,ab1) (aa2,ab3)(aa3,ab1) (aa3,ab2)This is the pairing algorithm I have written and it...
View ArticleBug when using typing & daemon threads
When I run this code on Python 3.11 it runs fine, but if I import typing_minimal (or typing) in reader.py I get this error:Fatal Python error: _enter_buffered_busy: could not acquire lock for...
View ArticleTrying to use the multiprocessing library in Python but I am running into...
So I've written this code after consulting chatgpt and it works for the most part:import numpy as npfrom sklearn.datasets import make_classificationfrom sklearn.model_selection import...
View Articlepytest, xdist, and sharing generated file dependencies
I have multiple tests that need require an expensive-to-generate file.I'd like the file to be re-generated on every test run, but no more than once.To complicate the matter, both these tests as well as...
View ArticleInsert only to specific fields in formModel in django
I have a django model and its corresponding form to insert into and read value from a table with three columns in database. My requirement is I only need to insert in to say two column using form,...
View ArticlePython: Multidimensional Arrays
Is this format a Multidimensional Array ?sales=[LastSale(date=datetime.datetime(2024, 3, 10, 21, 15, 53, tzinfo=datetime.timezone.utc), price='0.59'), LastSale(date=datetime.datetime(2024, 3, 9, 16,...
View ArticleHow can I speed up the process of integrating a complex function?
import numpy as npfrom scipy import integrateimport matplotlib.pyplot as pltimport datetimestart = datetime.datetime.now()plt.rcParams['axes.grid'] = TrueXX=[None, 11.3, 14.8, 7.6, 10.5, 12.7, 3.9,...
View ArticleHow to install local python modules in subdirectories as separate packages...
I have a repo with this structure:root_dir/├── python/│└── libraries/│└──types/│├── type1/││└── math/││└── math.py│└── type2/│└── categories/│└── category1/ │├── module1/││└── module1.py│├──...
View ArticleModifying values in .pdb file and save as new
for an assignment I have to read a small .pdb file in Python, change some values, and save it as a new .pdb file.My original file is like this:ATOM 19 HD2 TYR 1 26.910 61.717 39.871 1.00 0.00 H ATOM 20...
View Article