The ones listed are part of the program.
I want to multiply each element of the list (light) that represents the amount of solar radiation by a value, but I get an error with solar1 but with solar2. Where can I change it to improve it?
light1 = [1,2,3,4]
solar1 = [0.7 * 1 * Powerpv, 0.7 * 2 * Powerpv, 0.7 * 3 * Powerpv, 0.7 * 4 * Powerpv]
light2 = [[1,2,3,4], [5,6,7,8]]
solar2 = [0.7 * 1 * Powerpv, 0.7 * 2 * Powerpv, 0.7 * 3 * Powerpv, 0.7 * 4 * Powerpv], [0.7 * 5 * Powerpv, 0.7 * 6 * Powerpv, 0.7 * 7 * Powerpv, 0.7 * 8 * Powerpv]]
It is an image that looks like.
code
from __future__ import division
from pulp import LpVariable, LpProblem, LpStatus, lpSum, value
import numpy as np
import random, pulp
#PV parameters
Powerpv1 = LpVariable ('Powerpv', 0, None)
Powerpv2 = LpVariable ('Powerpv', 0, None)
light1 = [random.uniform (0, 10) for i in range (24)] #Insolation
solar1 = [0.7 * q * Powerpv1 for q in light1] #pv Power generation
n = 3 # number of repetitions
for k in range (n):
light2 = [[np.random.uniform (0,10) for i in range (24)] for k in range (n)] #Insolation
solar2 = [0.7 * r * Powerpv2 for r in light2] #pv Power generation
print (solar1)
print (solar2)
error
TypeError Traceback (most recent call last)
15 for k in range (n):
16 light2 = [[np.random.uniform (0,10) for i in range (24)] for k in range (n)] #Insolation
--->17 solar2 = [0.7 * r * Powerpv2 for r in light2] #pv Power generation
18
19 print (solar1)
15 for k in range (n):
16 light2 = [[np.random.uniform (0,10) for i in range (24)] for k in range (n)] #Insolation
--->17 solar2 = [0.7 * r * Powerpv2 for r in light2] #pv Power generation
18
19 print (solar1)
TypeError: can't multiply sequence by non-int of type'float'
-
Answer # 1
-
Answer # 2
Since light2 is a two-dimensional list,
solar2 = [0.7 * r * Powerpv2 for r in light2]
The r in is a list, and the multiplication has failed.Amendment 1: Make light2 a one-dimensional list
for k in range (n): light2 = [np.random.uniform (0,10) for i in range (24 * n)] #Insolation ★ Correction solar2 = [0.7 * r * Powerpv2 for r in light2] #pv Power generation
Amendment 2: Broadcast calculation of r as ndarry type
for k in range (n): light2 = [[np.random.uniform (0,10) for i in range (24)] for k in range (n)] #Insolation solar2 = [np.array (r) * 0.7 * Powerpv2 for r in light2] #pv Power generation ★ Correction
Related articles
- i can't get the python selenium element (i can get it when i open the chrom developer tools, but i can't get it when i close it)
- python - how to get the number of searches for a specific word within the period
- python - count by element with pivot_table in pandas
- python - how to accept number input even if keypressevent is defined for qlineedit in pyside
- i want to delete a partially matching element in a python array
- python - i want to add an element to a double list
- python - i want to retrieve the element above the element searched by soupfind_all in beautiful soup
- python - valueerror: field'id' expected a number but got'suzukitadashi'
- where is the minor version number of python that starts by default specified?
- i want to see the change of one element of a recurrence formula including a python matrix
- python - typeerror: can't multiply sequence by non-int of type'list'
- python - when you want to judge by the number of characters from the back with a regular expression
- python - i can't get the element with selenium
- python - sumy by specifying the maximum number of characters with sumy
- a large number of errors when installing the python library
- python - i want to add a line number to the data frame
- number of python combinations
- python - [ajax] i want to get and send the value of the button element in the form
- python 3x - i want to output the name corresponding to the number entered in the excel file
- python - i want to divide a binary number into two, store it in a list, and represent it in a different decimal number
I'm not sure what the Powerpv is, but it's probably because of the following error:
Since light2 has a list in the list, the list will come out just by extracting the element one step. And multiplying the list by an integer increments the list itself, not the numbers of the elements in the list.
So, if you want to make it work for the time being, is it like increasing the nesting as shown below?