Python Forum
Creating Vector from a Program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Vector from a Program
#1
Hello everyone.
I am a new programmer.
I am trying to create a vector called "pressure", below is an example for the calculations that I have been trying to do.
Below is just a small piece from my code, which is the part that I am trying to solve. Also I simplified the "formula".


 pressure = [] i = 1 p0 = 50 pcp0 = 20 n = 10 while i < n: p1 = p0 - 0.17 * pcp0 for pressure in i: pressure.append(p1) i = i + 1 p0 = p1 
The error is for pressure in i:
TypeError: 'int' object is not iterable
Reply
#2
(Oct-08-2019, 02:48 AM)ericvrocha Wrote: I am trying to create a vector called "pressure", below is an example for the calculations that I have been trying to do.

 pressure = [] i = 1 p0 = 50 pcp0 = 20 n = 10 while i < n: p1 = p0 - 0.17 * pcp0 for pressure in i: pressure.append(p1) i = i + 1 p0 = p1 
The error is for pressure in i:
TypeError: 'int' object is not iterable

Hi!

I find your code a bit strange.

First, your indentation seems to be wrong.

Second, we learnt at high school that a vector has 1 component if the vector is on a line, like v = (v1), 2 components if the vector is on a plane, like v = (v1, v2) and 3 components if the vector is in space, like v = (v1, v2, v3). I think you are trying to add 9 elements to your vector named 'pressure', from value i = 1 (line 3) to value i = 9 (lines 6, 7 and 11).

Third, your line 9:

for pressure in i:
has no sense to me, because it is just a single value at a time.

Fourth, on your line 8:

p1 = p0 - 0.17 * pcp0
p0 is a constant (p0 = 50), pcp0 is a constant (pcp0 = 20), so p1 is also a constant (p1 = (50) - (0.17 * 20) = 50 - 3.4 = 46.6) (it's independent of 'i' values, and it's not going to change).

Fifth, p0 = p1, is after what you intend to be a loop, so it's not going to change values in the loop either.

All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply
#3
ericvrocha Wrote:I am trying to create a vector called "pressure"
Can you describe which values the vector is supposed to contain?

newbieAuggie2019 Wrote:we learnt at high school that a vector has 1 component ...
It is true but in general a vector can have as many components as one wants. Such vectors simply live in higher dimensional spaces.
Reply
#4
(Oct-08-2019, 07:20 AM)Gribouillis Wrote:
newbieAuggie2019 Wrote:we learnt at high school that a vector has 1 component ...
It is true but in general a vector can have as many components as one wants. Such vectors simply live in higher dimensional spaces.
Thank you!

Here I'm learning many things, among them, that one cannot take as eternal truths, things that you have been taught by your teachers, or even things that you have been reading in supposedly good specialistic books.

Thanks again for enlightening me!

All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a Mindmap program J_Miller 4 10,825 Sep-23-2025, 12:00 PM
Last Post: Pedroski55
Question How to understand the vector/direction mason321 0 1,960 Dec-14-2021, 10:57 PM
Last Post: mason321
  How to find vector of a 3D plot mason321 0 1,730 Nov-13-2021, 05:05 PM
Last Post: mason321
  creating simplex tableau pivot program easy or difficult for a beginner in Python? alex_0 2 4,102 Mar-31-2021, 03:39 AM
Last Post: Larz60+
  How do I make a symmetric matrix from a column vector? leocsmith 3 6,066 Mar-30-2021, 10:17 AM
Last Post: leocsmith
  3D vector class with inheritance from 2D vector class buss0140 4 5,166 Dec-20-2020, 08:44 PM
Last Post: deanhystad
  Issue with def norm in class Vector DimosG 4 4,152 Mar-26-2020, 05:03 PM
Last Post: DimosG
  Make dual vector dot-product more efficient technossomy 3 4,072 Nov-28-2019, 09:27 PM
Last Post: Gribouillis
  Inaccurate result when a vector is divided by a matrix FromTheColdNorth 3 3,371 Oct-29-2019, 12:06 AM
Last Post: scidam
  creating hex dump modifying program ensoniq 3 4,667 Oct-14-2019, 08:21 AM
Last Post: Larz60+

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.