I am troubling with the code section given below.. when I execute it, I get value error given below.
Segmask = result2
box=[]
[liver_res, num] = measure.label(result1, return_num=True)
region = measure.regionprops(liver_res)
for i in range(num):
box.append(region[i].area)
label_num = box.index(max(box)) + 1
liver_res[liver_res != label_num] = 0
liver_res[liver_res == label_num] = 1
Value error:
Traceback (most recent call last):
File "/content/gdrive/My Drive/LiTS/test.py", line 122, in <module>
predict(args)
File "/content/gdrive/My Drive/LiTS/test.py", line 91, in predict
label_num = box.index(max(box)) + 1
ValueError: max() arg is an empty sequence
Related
for product_row in worksheet.iter_rows(min_row=2,
max_row=worksheet.max_row,
min_col=1,
max_col=5, values_only=True):
test_write = worksheet.cell(product_row,5)
test_write.value = 5
Gives me this error:
Traceback (most recent call last):
File "C:\pythonProject\main.py", line 62, in <module>
test_write = worksheet.cell(product_row,5)
File "C:\pythonProject\venv\lib\site-packages\openpyxl\worksheet\worksheet.py", line 237, in cell
if row < 1 or column < 1:
TypeError: '<' not supported between instances of 'tuple' and 'int'
But when I have this:
for product_row in range(2, worksheet.max_row+1):
test_write = worksheet.cell(product_row,5)
test_write.value = 5
I do not get any error. What am I doing wrong?
Running the example code in the pyrplidar documentation
from pyrplidar import PyRPlidar
lidar = PyRPlidar()
lidar.connect(port="COM8", baudrate=256000, timeout=3)
# Linux : "/dev/ttyUSB0"
# MacOS : "/dev/cu.SLAB_USBtoUART"
# Windows : "COM5"
info = lidar.get_info()
print("info :", info)
health = lidar.get_health()
print("health :", health)
samplerate = lidar.get_samplerate()
print("samplerate :", samplerate)
scan_modes = lidar.get_scan_modes()
print("scan modes :")
for scan_mode in scan_modes:
print(scan_mode)
lidar.disconnect()
give this error message
Traceback (most recent call last):
File "C:\Users\ADMIN\Desktop\RPlidar\test1.py", line 10, in <module>
info = lidar.get_info()
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrplidar.py", line 73, in get_info
discriptor = self.receive_discriptor()
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrplidar.py", line 42, in receive_discriptor
discriptor = PyRPlidarResponse(self.lidar_serial.receive_data(RPLIDAR_DESCRIPTOR_LEN))
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrplidar_protocol.py", line 110, in __init__
self.sync_byte1 = raw_bytes[0]
IndexError: index out of range
How do I solve this? Please help
def get_playlist_tracks(username, playlist_id):
results = sp.user_playlist_tracks(username,playlist_id)
playlist_items = results['items']
uris = []
while results['next']:
results = sp.next(results)
playlist_items.append(results['items'])
for item in playlist_items:
track_uri = item["track"]["uri"]
uris.append(track_uri)
return uris
get_playlist_tracks('iKetu', '7h10RuUjKqfqwWibESmwy1')
print(uris)
The Output I get is
PS C:\Users\iketu\Music\Elite\Album Artworks> & C:/Users/iketu/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/iketu/Music/Elite/Album Artworks/getAlbumArt.py"
Traceback (most recent call last):
File "c:/Users/iketu/Music/Elite/Album Artworks/getAlbumArt.py", line 27, in <module>
get_playlist_tracks('iKetu', '7h10RuUjKqfqwWibESmwy1')
File "c:/Users/iketu/Music/Elite/Album Artworks/getAlbumArt.py", line 23, in get_playlist_tracks
track_uri = item["track"]["uri"]
TypeError: list indices must be integers or slices, not str
I am trying to calculate IRR and its giving me result in command line but whenever I am trying to pass the values as a parameter its failing with below error
Code
import numpy
import sys
def irrYearly(array):
array = [array]
irr = round(numpy.irr(array), 2)*100
return irr
def irrCal(tenure, array):
if tenure == "Yearly":
# return irrYearly(array)
# array = [-30000, -30000, -30000, -30000, -30000, 107180] -- if I uncomment this line its works fine
print(irrYearly(array))
elif tenure == "Monthly":
# return irrMonthly(array)
print(irrMonthly(array))
def main():
if len(sys.argv) == 3:
tenure = sys.argv[1]
array = sys.argv[2]
irrCal(tenure, array)
main()
Error
Please find the error
C:\Python27\python.exe C:/Users/abhis/PycharmProjects/IRR/irr.py Yearly -30000.00,-30000.00,-30000.00,-30000.00,-30000.00,107180.00
Traceback (most recent call last):
File "C:/Users/abhis/PycharmProjects/IRR/irr.py", line 74, in <module>
['-30000.00,-30000.00,-30000.00,-30000.00,-30000.00,107180.00']
main()
File "C:/Users/abhis/PycharmProjects/IRR/irr.py", line 64, in main
irrCal(tenure, array)
File "C:/Users/abhis/PycharmProjects/IRR/irr.py", line 49, in irrCal
print(irrYearly(array))
File "C:/Users/abhis/PycharmProjects/IRR/irr.py"", line 19, in irrYearly
irr = round(numpy.irr(array), 2)*100
File "C:\Python27\lib\site-packages\numpy\lib\financial.py", line 669, in irr
res = np.roots(values[::-1])
File "C:\Python27\lib\site-packages\numpy\lib\polynomial.py", line 222, in roots
p = p.astype(float)
ValueError: invalid literal for float(): -30000.00,-30000.00,-30000.00,-30000.00,-30000.00,107180.00
argv[2] is a string with comma separated values, but to numpy it's a string not a list of floats. You first need to convert it like so:
float_vals = [float(x) for x in argv[2].split(",")].
import random
foundwords = []
wordsDict = {}
with open("text", "r") as file:
contents = file.read().replace('\n',' ')
words = contents.split(' ')
def findwords(word):
for i in range(len(words) - 1):
if words[i] == word:
if not words[i + 1] == '':
foundwords.append(words[i + 1])
return foundwords
for word in words:
wordsDict.setdefault(word, findwords(word))
# for i in range(len(words) - 1):
# findwords(words[i])
# wordsDict.setdefault(words[i], foundwords)
# del foundwords[:]
def nextword(word):
wordList = wordsDict.get(word.lower())
new = wordList[random.randint(0, len(wordList) - 1)]
return new
def assemble():
final = [words[random.randint(0, len(words))].capitalize()]
final.append(nextword(final[-1]))
print(final)
assemble()
I have tried to create a markov-chain project, however, I get the following error:
Traceback (most recent call last):
File "main.py", line 32, in <module>
assemble()
File "main.py", line 28, in assemble
final.append(nextword(final[0]))
File "main.py", line 23, in nextword
new = wordList[random.randint(0, len(wordList) - 1)]
File "/usr/local/lib/python3.6/random.py", line 220, in randint
return self.randrange(a, b+1)
File "/usr/local/lib/python3.6/random.py", line 198, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,0, 0)
exited with non-zero status
And sometimes this error:
Traceback (most recent call last):
File "main.py", line 31, in <module>
assemble()
File "main.py", line 28, in assemble
final.append(nextword(final[0]))
File "main.py", line 23, in nextword
new = wordList[random.randint(0, len(wordList) - 1)]
TypeError: object of type 'NoneType' has no len()
I have no idea how to start fixing this problem. I'm only a beginner programmer, so if my code is inefficient or anything, I apologize. Also, I'm not sure if this ok to post as a question, sorry.