After searching on the internet, I know how to create a 1*j struct array. For example,
>> patient(1).name = 'John Doe';
patient(1).billing = 127.00;
patient(1).test = [79, 75, 73; 180, 178, 177.5; 220, 210, 205];
>>
>> patient(2).name = 'Ann Lane';
patient(2).billing = 28.50;
patient(2).test = [68, 70, 68; 118, 118, 119; 172, 170, 169];
My question is: how to create a j*1 struct array? Thanks so much for your time and attention.
There are two solutions:
You transpose your structure array afterwards:
patient = patient';
You index your structure array with two integers (first=row, second=column):
patient(j,1).name = 'John Doe';
Best,
Related
I want to save array of my object in file in python and I test pickle, numpy,..but it doesn't work.
my class that I want to save instance of it in file is:
class pesrson():
def __init__(self,name,centralwidget):
self.name=name
self.centralwidget=centralwidget
def config(self):
self.frame_eployee = QFrame(self.centralwidget)
self.frame_eployee.setObjectName(u"frame_eployee")
self.frame_eployee.setGeometry(QRect(20, 590, 321, 51))
self.frame_eployee.setStyleSheet(u"color:rgb(85, 170, 255)")
self.frame_eployee.setFrameShape(QFrame.StyledPanel)
self.frame_eployee.setFrameShadow(QFrame.Raised)
self.label_fix_logo_user = QLabel(self.frame_eployee)
self.label_fix_logo_user.setObjectName(u"label_fix_logo_user")
self.label_fix_logo_user.setGeometry(QRect(10, 0, 41, 41))
self.label_fix_logo_user.setPixmap(QPixmap(u"D:/V2.0.0/Programme/qt/UI design/picture/user.svg"))
self.label_name_employee = QLabel(self.frame_eployee)
self.label_name_employee.setObjectName(u"label_name_employee")
self.label_name_employee.setGeometry(QRect(60, 10, 101, 21))
self.label_name_employee.setStyleSheet(u"color: rgb(255, 255, 255);\n"
"font: 25 10pt \"Segoe UI Light\";")
self.label_tim_login = QLabel(self.frame_eployee)
self.label_tim_login.setObjectName(u"label_tim_login")
self.label_tim_login.setGeometry(QRect(190, 10, 61, 21))
self.label_tim_login.setStyleSheet(u"color: rgb(255, 255, 255);\n"
"font: 25 10pt \"Segoe UI Light\";")
self.label_time_logOut = QLabel(self.frame_eployee)
self.label_time_logOut.setObjectName(u"label_time_logOut")
self.label_time_logOut.setGeometry(QRect(250, 10, 61, 21))
self.label_time_logOut.setStyleSheet(u"color: rgb(255, 255, 255);\n"
"font: 25 10pt \"Segoe UI Light\";")
self.label_name_employee.setText(QCoreApplication.translate("MainWindow", self.name, None))
self.label_tim_login.setText(
QCoreApplication.translate("MainWindow", u"<html><head/><body><p align=\"center\">08:34</p></body></html>",
None))
self.label_time_logOut.setText(
QCoreApplication.translate("MainWindow", u"<html><head/><body><p align=\"center\">08:34</p></body></html>",
None))
return self.frame_eployee
I create this object with this code:
p=pesrson("faezeh",self.ui.centralwidget)
self.ui.verticalLayout.addWidget(p.config())
self.tree.append(p)
now I want to save this array then read them and can use all attributes.
this error is when I use json :
TypeError: Object of type person is not JSON serializable
<employee.pesrson object at 0x000001DD17C7B7F0>
this error when I use pickle:
Possibly unsupported): cannot pickle 'PySide2.QtWidgets.QFrame' object
you could use the pickle module in the standard library and also you could use a database instead of a file. I think it would fit your problem.
table name: muscle_groups
fields: id, name, segment_ids
data:
{"f": [], "m": [31, 32, 33, 34, 35, 36, 38, 39]}
tried many variations like:
select id, name, segment_ids->>"m"
where 5 = any(json_array_element(segment_ids->>"m")
You are looking for the contains operator #>
select *
from muscle_groups
where segment_ids #> '{"m": [5]}'
sorry for my annoying questions again.
Having a bit of trouble with some code. The task is to write a function that takes a nested list of currency conversions and turn it into a table (I've attached some pictures for clarification)
(could only attach one image, this is the nested list it converts)
[[10, 9.6, 7.5, 6.7, 4.96], [20, 19.2, 15.0, 13.4, 9.92], [30, 28.799999999999997, 22.5, 20.1, 14.879999999999999], [40, 38.4, 30.0, 26.8, 19.84], [50, 48.0, 37.5, 33.5, 24.8], [60, 57.599999999999994, 45.0, 40.2, 29.759999999999998], [70, 67.2, 52.5, 46.900000000000006, 34.72], [80, 76.8, 60.0, 53.6, 39.68], [90, 86.39999999999999, 67.5, 60.300000000000004, 44.64], [100, 96.0, 75.0, 67.0, 49.6]]
I've got the Header column for the table to work fine.
I'm having issues when I'm trying to iterate over each sublist in the nested list, convert it to a string (and two decimal places) and with a tab between each entry.
the code I've got so far is:
def printTable(cur):
list2 = makeTable(cur)
lst1 = Extract(cur)
lst1.insert(0, "$NZD")
lne1 = "\t".join(lst1)
print(lne1)
list=map(str,list2)
print(list2)
for list in list2:
for elem in list:
linelem = "\t".join(elem)
print(linelem)
printTable(cur)
(Note: The first function I call and assign to list2 is what generates the data/nested list)
I've tried playing around a bit but I keep coming up with different error messages trying to convert each sublist to a string.
Thank you all for your help!![enter image description here][1]
Try using this method;
import pandas as pd
import csv
with open("out.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(a)
pd.read_csv("out.csv", header = [col1, col2, col3, col4, col5])
I want to give an input, a video which was taken from picamera(.h264) to my python code in my PC, [as opencv-python is not getting installed in my raspbian OS].
I converted the video which was in .h264 to mp4 and gave that as input video file,and I get the below error.
OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file /io/opencv/modules/core/src/arithm.cpp, line 659
Traceback (most recent call last):
File "/home/ramakrishna/PycharmProjects/Lanedect/driving-lane-departure-warning-master/main.py", line 36, in <module>
clip = clip1.fl_image(process_frame) #NOTE: it should be in BGR format
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/video/VideoClip.py", line 533, in fl_image
return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/Clip.py", line 136, in fl
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "<decorator-gen-57>", line 2, in set_make_frame
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/decorators.py", line 14, in outplace
f(newclip, *a, **k)
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/video/VideoClip.py", line 694, in set_make_frame
self.size = self.get_frame(0).shape[:2][::-1]
File "<decorator-gen-14>", line 2, in get_frame
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/Clip.py", line 95, in get_frame
return self.make_frame(t)
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/Clip.py", line 136, in <lambda>
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "/home/ramakrishna/.local/lib/python3.4/site-packages/moviepy/video/VideoClip.py", line 533, in <lambda>
return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
File "/home/ramakrishna/PycharmProjects/Lanedect/driving-lane-departure-warning-master/lane.py", line 619, in process_frame
output = create_output_frame(offcenter, pts, img_undist_, fps, curvature, curve_direction, binary_sub)
File "/home/ramakrishna/PycharmProjects/Lanedect/driving-lane-departure-warning-master/lane.py", line 486, in create_output_frame
output = cv2.addWeighted(undist_ori, 1, newwarp_, 0.3, 0)
cv2.error: /io/opencv/modules/core/src/arithm.cpp:659: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function arithm_op
Process finished with exit code 1
Please help me solve this error.
Below are the size of input file already set in the code.But my video file size is 20.5 MB and dimensions 1920 x 1080. How can I change the dimensions if I have to?
left_lane = Lane()
right_lane = Lane()
frame_width = 1280
frame_height = 720
LANEWIDTH = 3.7 # highway lane width in US: 3.7 meters
input_scale = 4
output_frame_scale = 4
N = 4 # buffer previous N lines
# fullsize:1280x720
x = [194, 1117, 705, 575]
y = [719, 719, 461, 461]
X = [290, 990, 990, 290]
Y = [719, 719, 0, 0]
The objective is to create timers for League of Legends. It has jungle camps; each one respawns a certain time after killing it.
For this I want to activate the same function for multiple timers at the same time. If I kill blue buff and wolves at the same time I want timers for both of them (click the blue golem's button for my wolves to get the same timer).
I haven't implemented the wolves button but do have a start button. Clicking the blue button starts my timer, but following it up with a click on start game button just queues it until after first timer finishes.
I looked into the wiki page. But I don't want to stop the running timer; I want to run another at the same time. Are there coding errors, better ways of doing things, etc.? Here is my code:
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Timers.au3>
;==> Set our $font variable
Global $font
$font = "Arial Black"
;==> Create our Graphic User Interface
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Jungle Timers Deluxe", 200, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$startbutton = GUICtrlCreateButton("Start Game", 50, 10, 70)
$ybluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 10, 40, 50, 50, $BS_MULTILINE)
$yredbuff = GUICtrlCreateButton("Lizard Elder (Red)", 10, 110, 50, 50, $BS_MULTILINE)
$ywraiths = GUICtrlCreateButton("Lizard Elder (Red)", 10, 180, 50, 50, $BS_MULTILINE)
$ywolves = GUICtrlCreateButton("Lizard Elder (Red)", 10, 250, 50, 50, $BS_MULTILINE)
$ydgolems = GUICtrlCreateButton("Lizard Elder (Red)", 10, 320, 50, 50, $BS_MULTILINE)
$ebluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 100, 40, 50, 50, $BS_MULTILINE)
$eredbuff = GUICtrlCreateButton("Lizard Elder (Red)", 100, 110, 50, 50, $BS_MULTILINE)
$ewraiths = GUICtrlCreateButton("Lizard Elder (Red)", 100, 180, 50, 50, $BS_MULTILINE)
$ewolves = GUICtrlCreateButton("Lizard Elder (Red)", 100, 250, 50, 50, $BS_MULTILINE)
$edgolems = GUICtrlCreateButton("Lizard Elder (Red)", 100, 320, 50, 50, $BS_MULTILINE)
;==> Create our events
GUICtrlSetOnEvent($startbutton, "StartGame")
GUICtrlSetOnEvent($ybluebuff, "yBlueBuff")
;==> Display our Graphic User Interface.
GUISetState(#SW_SHOW)
While 1
Sleep(1000) ; Idle around
WEnd
Func yBlueBuff()
Dim $bluetimer = 10
$i = 1
$ybb = GUICtrlCreateLabel("Your Blue Buff:", 10, 40)
GUICtrlDelete($ybluebuff)
$ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
While $i <= $bluetimer
GUICtrlDelete($ybblabel)
If $i >= 5 Then
$ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
GUICtrlSetFont(-1, 22, 500, $font)
GUICtrlSetBkColor($ybblabel, 0xFFCCCC)
$i = $i + 1
ElseIf $i < 5 Then
$ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
GUICtrlSetFont(-1, 22, 500, $font)
$i = $i + 1
EndIf
Sleep(1000)
WEnd
GUICtrlDelete($ybblabel)
GUICtrlDelete($ybb)
$ybluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 10, 40, 50, 50, $BS_MULTILINE)
EndFunc ;==>yBlueBuff
Func StartGame()
; Activate your League Window
WinActivate("[CLASS:Notepad]")
; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
WinWaitActive("[CLASS:Notepad]")
; Now that the Notepad window is active type some text
Send("{ENTER}Baron spawns in 15, Dragon spawns at 2:30{ENTER}")
Sleep(500)
Send("{ENTER}Wraiths/Wolves/Double Golems spawn at 1:40. Red & Blue spawn at 1:55{ENTER}")
Sleep(500)
EndFunc ;==>StartGame
Func CLOSEClicked()
;Note: at this point #GUI_CTRLID would equal $GUI_EVENT_CLOSE,
;and #GUI_WINHANDLE would equal $mainwindow
MsgBox(0, "GUI Event", "Thanks for using Jungle Timers Deluxe!")
Exit
EndFunc ;==>CLOSEClicked
; Finished!
I built this off the Notepad example tutorials and use Notepad because it is easier to debug.
AutoIt does not support running two functions simultaneously, otherwise known as multithreading.
Here is their explanation: AutoItNotOnToDoList
In order for your program to work, you would have to be able to constantly monitor whether or not a button is being pressed and at the same time execute the functions that are called by the buttons.
Although it is not technically mulithreading, a workaround for this problem is running multiple scripts at the same time.
Are there ... better ways of doing things, etc.?
Example demonstrating multiple timers (and responsive GUI) :
#include <GUIConstantsEx.au3>; $GUI_EVENT_CLOSE
#include <Timers.au3>
Global Enum $TMR_NAME, _
$TMR_TIME, _
$TMR_STAMP, _
$TMR_STATE, _
$TMR_PROGR, _
$TMR_BTN, _
$TMR__ENUM
Global $g_aTimer[3][$TMR__ENUM]
$g_aTimer[0][$TMR_NAME] = 'Timer A'
$g_aTimer[0][$TMR_TIME] = 60
$g_aTimer[1][$TMR_NAME] = 'Timer B'
$g_aTimer[1][$TMR_TIME] = 30
$g_aTimer[2][$TMR_NAME] = 'Timer C'
$g_aTimer[2][$TMR_TIME] = 10
Main()
Func Main()
Local $iMsg = 0
Local $hGui
GuiMain($hGui, 400, 25)
While True
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case Else
ButtonCheck($iMsg)
EndSwitch
TimerUpdate()
WEnd
GUIDelete($hGui)
Exit
EndFunc
Func GuiMain(ByRef $hGui, Const $iWidth, Const $iHeightTimer)
Local Const $iAmount = UBound($g_aTimer)
$hGui = GUICreate(#ScriptName, $iWidth, $iHeightTimer * 2 * $iAmount)
For $i1 = 0 To $iAmount - 1
$g_aTimer[$i1][$TMR_BTN] = GUICtrlCreateButton($g_aTimer[$i1][$TMR_NAME], 0, $i1 * ($iHeightTimer * 2), $iWidth / 2, $iHeightTimer)
$g_aTimer[$i1][$TMR_PROGR] = GUICtrlCreateProgress(0, $iHeightTimer + $i1 * ($iHeightTimer * 2), $iWidth, $iHeightTimer)
Next
GUISetState(#SW_SHOW, $hGui)
EndFunc
Func ButtonCheck(Const $iMsg)
For $i1 = 0 To UBound($g_aTimer) - 1
If $iMsg = $g_aTimer[$i1][$TMR_BTN] Then
$g_aTimer[$i1][$TMR_STATE] = True
$g_aTimer[$i1][$TMR_STAMP] = _Timer_Init()
ExitLoop
EndIf
Next
EndFunc
Func TimerUpdate()
Local $nDiff
For $i1 = 0 To UBound($g_aTimer) - 1
If Not $g_aTimer[$i1][$TMR_STATE] Then ContinueLoop
$nDiff = _Timer_Diff($g_aTimer[$i1][$TMR_STAMP]) / ($g_aTimer[$i1][$TMR_TIME] * 1000) * 100
If $nDiff > 100 Then
$nDiff = 100
$g_aTimer[$i1][$TMR_STATE] = False
EndIf
GUICtrlSetData($g_aTimer[$i1][$TMR_PROGR], $nDiff)
Next
EndFunc