Mr. Toç
Mr. Toç

Reputation: 21

I cannot find why my list is not as a variable

Ss = [0.806, 0.773, 1.1014, 0.786, 1.095, 0.803, 
      0.806, 0.785, 1.014, 0.586, 0.955, 1.088, 
      0.752, 1.010, 1.246, 0.879, 1.284]
S1 = [0.228, 0.220, 0.280, 0.231, 0.297, 0.226,
      0.228, 0.231, 0.280, 0.174, 0.264, 0.295, 
      0.217, 0.279, 0.338, 0.247, 0.351]
Fs = [1.200, 1.200, 1.094, 1.200, 0.800, 1.200, 
      1.200, 1.200, 1.094, 1.266, 1.118, 1.065, 
      1.200, 1.096, 1.200, 0.800, 0.900]
F1 = [1.500, 1.500, 2.040, 1.500, 0.800, 1.500,
      1.500, 1.500, 2.040, 1.500, 2.072, 2.010, 
      1.500, 2.042, 1.500, 0.800, 0.800]

SDS = []                # Short Term Design Acceleration Constant (Dimensionless)
SD1 = []                # 1 second Period Design Acceleration Constant (Dimensionless)

for i in range(len(F1)):
    SDS.append(Ss[i]*Fs[i])
for i in range(len(F1)):
    SD1.append(S1[i]*F1[i])

I am using Anaconda - Spyder. SDS and SD1 lists are not demonstrated as a variable. I could not find my mistake. I also try to open in Python IDLE, but it is still giving the same mistake. If there is any missing punctuation, please say it.

Upvotes: 1

Views: 68

Answers (1)

borosdenes
borosdenes

Reputation: 73

The code itself creates the two lists, SDS and SD1 (i.e. the issue is not with the Python code). If you're trying to inspect these variables in Spyder's Variable Explorer (which you didn't state, but I assume here), and you can not find them, make sure

Honestly, I'm not a Spyder user, so I may be missing something.


P.S.: you could make the for loops more pythonic by iterating using zip (including an example for the first loop). You can name ss_element and fs_element however you like.

for ss_element, fs_element in zip(Ss, Fs):
    SDS.append(ss_element * fs_element)

Or even better, list comprehension.

SDS = [ss_element * fs_element for ss_element, fs_element in zip(Ss, Fs)

But the most pythonic way would be to use a library which enables clean element-wise operations, like numpy.

import numpy as np

Ss = np.array([0.806, 0.773, 1.1014, 0.786, 1.095, 0.803, 
               0.806, 0.785, 1.014, 0.586, 0.955, 1.088, 
               0.752, 1.010, 1.246, 0.879, 1.284])
Fs = np.array([1.200, 1.200, 1.094, 1.200, 0.800, 1.200, 
               1.200, 1.200, 1.094, 1.266, 1.118, 1.065, 
               1.200, 1.096, 1.200, 0.800, 0.900])

SDS = Ss * Fs

Upvotes: 1

Related Questions