Questions tagged [python]

Programming questions are off-topic here. Do not ask questions about how to write code in Python. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

215 questions
1
vote
1 answer

A problem about slicing and indexing in numpy in Python

I learned that in numpy, given a vector, slicing and indexing could give different results. I ran the following codes: a = np.array([1, 2]) b = np.array([3, 4, 5]) print(b[a]) c = b[1:] print(b) c[0] = 1 print(b) print(c) print(b[1:] is c) and get…
Edward Wang
  • 113
  • 3
1
vote
1 answer

Truth value of a proposition

I'm trying to write a function in Python that takes it argument as a Python list and returns a boolean value based on the truth vale of the proposition $E(x) \to \exists y \text{ s.t. } x=2y$, where here the proposition $E(x)$ means 'x is…
1
vote
1 answer

What is the practical use of list.clear() method in Python?

I was wondering if there is a reason behind clearing all the values in a list and reusing it, as opposed to deleting the list and creating a new one. Are there any practical advantages of using clear() method, aside from situations where the list is…
1
vote
1 answer

Sympy does not recognise when two partial derivatives happen to be equal

I am trying to find the first and second-order partial derivatives of a function of four variables $S$ using pythons symbolic math package sympy. The issue is that sympy does not automatically see that certain pairs of partial derivatives, when…
1
vote
1 answer

Why don't we recognize Python as a compiler-based language?

I just read this Why doesn't Python need a compiler? I know that Python isn't absolutely compiler or interpreted but it is both of them it's maybe an interpretive, high-level, and all-purpose programming language. Python uses PVM(interpreter) and…
jasmine
  • 19
  • 6
1
vote
0 answers

Conversion of a YAML file to XLSX using Python

I want to convert a set of yaml files in a folder into an xlsx file. I thought I'd start with trying to convert one yaml file into an xlsx file. The yaml files in the folder are all in the format given below: info: city: Bangalore …
Seshank K
  • 11
  • 1
1
vote
2 answers

parse datetime number in html field

This is a sample of datetime field: 1615717137369 It means 2 days ago (from 16 march, 13:24) How can I parse the number? P.S: These are some examples: 16 15 89 8678037 16 March 16:15 ( 5 min ago) 16 15 89 8259356 16 March 16:08 (12 min…
1
vote
1 answer

Meaning of this python modulo operator exercise?

I just got started with Python PCEP course material on netacad.com. I've come across the following exercises: 2 % -4 = -2 2 % 4 = 2 As I understand it, the modulo operator returns the remainder of a division. So 2 divided by (-4) gives…
1
vote
4 answers

Quadratic equations using 2 different approaches

I am reading Mark Newman's Computational Physics and at chapter 4 page 133 in Exercise 4.2 he asks a) Write a program that takes as input three numbers, a, b, and c, and prints out the two solutions to the quadratic equation $ax^2 + bx + c = 0$…
seVenVo1d
  • 113
  • 4
1
vote
1 answer

After how many iterations will an integer circle back to 0 in Python?

If this question is completely garbage I apologize because I am new to CS and haven't understood at how programming languages (Python specifically) work. I was reading about how in a standard two-byte representation of a number, if one was to…
0
votes
1 answer

list('\a','\b','\c') prints '\x07', '\x08', '\\c'

In python3.6, I tried In [60]: a = '\a' In [61]: b = '\b' In [62]: c = '\c' In [63]: l =[a, b, c] If test l In [64]: l #it output following list instead of ['a','\b','\c'] Out[64]: ['\x07', '\x08', '\\c'] encapsulate them directly in a list. In…
Wizard
  • 173
  • 2
  • 7
0
votes
0 answers

How do one decide topic for first data analysis project?

Suppose an absolute beginner (in the field of data analysis/data science), which is indeed my case, has decided to create a project for his/her resume. These are the skills he has learnt: Python(Pandas, NumPy, Seaborn/Matplotlib) - 2 years of…
0
votes
0 answers

Networks and Internet Systems

I'm currently preparing for a final exam in Networks and Internet Systems. I don't have a large background knowledge on the topics, so I'm attempting to use python to approach the majority of question in the exam. I had an original series of code…
Kate
  • 1
  • 1
0
votes
0 answers

A practical issue in the code of HackerRank Restaurant problem

Problem Statement Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size $\ell \times b$ into smaller identical pieces such that each piece is a square having maximum possible side length with no…
0
votes
0 answers

render = font.render(text, 1, (0, 0, 0)) pygame.error: Library not initialized

the error im receiving is : file "/home/lucas/python/cargame/utils.py", line 17, in blit_text_center render = font.render(text, 1, (0, 0, 0)) pygame.error: Library not initialized the problem which seems to be somewhere in this piece of code: def…
LEJP
  • 1
1
2