Wrong number of arguments when a calling function from class in Python
I'm trying to write an implementation of a genetic algorithm in python. It
says there I am calling it with two arguments when only one is allowed,
but I'm sure I'm not.
Here is the relevant code:
class ga:
def __init__(self, best, pops=100, mchance=.07, ps=-1):
import random as r
self.pop = [[] for _ in range(pops)]
if ps == -1:
ps = len(best)
for x in range(len(self.pop)): #Creates array of random characters
for a in range(ps):
self.pop[x].append(str(unichr(r.randint(65,122))))
def mutate(array):
if r.random() <= mchance:
if r.randint(0,1) == 0:
self.pop[r.randint(0, pops)][r.randint(0, ps)] +=1
else:
self.pop[r.randint(0, pops)][r.randint(0, ps)] -=1
This is the code when I initialize and call from the class:
a = ga("Hello",10,5)
a.mutate(a.pop)
which returns the following error from IDLE:
TypeError: mutate() takes exactly 1 argument (2 given)
How can I fix this?
Bucco
Sunday, 1 September 2013
Go basics: What is the diference between calling a method on struct and calling it on a pointer to that struct?
Go basics: What is the diference between calling a method on struct and
calling it on a pointer to that struct?
Supoose that I have a Vertex type
type Vertex struct {
X, Y float64
}
and I've defined a method
func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
What's the difference between those two calls ? (both of them return the
same result)
v1 := Vertex{3, 4}
fmt.Println(v1.Abs())
v2 := &Vertex{3, 4}
fmt.Println(v2.Abs())
calling it on a pointer to that struct?
Supoose that I have a Vertex type
type Vertex struct {
X, Y float64
}
and I've defined a method
func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
What's the difference between those two calls ? (both of them return the
same result)
v1 := Vertex{3, 4}
fmt.Println(v1.Abs())
v2 := &Vertex{3, 4}
fmt.Println(v2.Abs())
Eclipse, GIT branches, Working Sets and Target Platform why Egit sucks in this.
Eclipse, GIT branches, Working Sets and Target Platform why Egit sucks in
this.
I am looking for a way to work with different GIT branches and have the
Eclipse workspace in sync. with the directory structure of the GIT
branches. In this case the branches will differ as projects have moved
around from subdirectoris. To illustrate:
master
plugins
plugin1
plugin2
feature1
topic_organize
plugins
plugin1
plugin2
features
feature1
I think the current Egit solution is not workable. What it does it close
projects which are not in the new branch. (When I switch branches in the
cmd line, is even more horrific, Egit actually recreates the missing
projects! in this case, when I switch to branch "topic_organize", the
project feature1 in plugins will be recreated by EGit, my repo is
automatically not clean which I sincerely despise, when switching to a
branch).
What it doesn't do (and should do) is to start with a clean workspace, and
import all the projects and organize them in working sets and on top load
the appropriate target platform.
The consequence of not doing what is should is, that I have to 1) manually
import missing projects, 2) remove projects created by EGit which are in
my repo, but not imported in the workspace. 3) Create working sets if
these differ between branches. (In my case the working sets, are equal to
the sub-dirs in the repository). 4) Clean my GIT repo.
As a best-practise towards a full solution is to create a team project
set. The working steps would be.
Import your projects from GIT and add them to working sets corresponding
to the directories in the GIT repo.
Export a Team Project set to a special project. (Make sure the location of
this project never moves in GIT).
Commit this "team" project, so your GIT branch is clean.
Clean your workspace. (I mean start with a clean workspace by removing all
working sets and projects).
Switch branch on the command line (You won't be able to switch with a
clean workspace).
Select file import, import Team Project Set (.psf) file. (Assuming you did
step 1,2,3 for the other branch as well).
tada your workspace is back with working sets and all projects open.
Change your target platform if needed.
NOW MY QUESTION :P
Do I miss something? Is this there a way to clean the workspace in one go?
Now I have to remove the working sets first, then the projects by
selecting them one by one! (Perhaps I should switch the workspace as
well?).
this.
I am looking for a way to work with different GIT branches and have the
Eclipse workspace in sync. with the directory structure of the GIT
branches. In this case the branches will differ as projects have moved
around from subdirectoris. To illustrate:
master
plugins
plugin1
plugin2
feature1
topic_organize
plugins
plugin1
plugin2
features
feature1
I think the current Egit solution is not workable. What it does it close
projects which are not in the new branch. (When I switch branches in the
cmd line, is even more horrific, Egit actually recreates the missing
projects! in this case, when I switch to branch "topic_organize", the
project feature1 in plugins will be recreated by EGit, my repo is
automatically not clean which I sincerely despise, when switching to a
branch).
What it doesn't do (and should do) is to start with a clean workspace, and
import all the projects and organize them in working sets and on top load
the appropriate target platform.
The consequence of not doing what is should is, that I have to 1) manually
import missing projects, 2) remove projects created by EGit which are in
my repo, but not imported in the workspace. 3) Create working sets if
these differ between branches. (In my case the working sets, are equal to
the sub-dirs in the repository). 4) Clean my GIT repo.
As a best-practise towards a full solution is to create a team project
set. The working steps would be.
Import your projects from GIT and add them to working sets corresponding
to the directories in the GIT repo.
Export a Team Project set to a special project. (Make sure the location of
this project never moves in GIT).
Commit this "team" project, so your GIT branch is clean.
Clean your workspace. (I mean start with a clean workspace by removing all
working sets and projects).
Switch branch on the command line (You won't be able to switch with a
clean workspace).
Select file import, import Team Project Set (.psf) file. (Assuming you did
step 1,2,3 for the other branch as well).
tada your workspace is back with working sets and all projects open.
Change your target platform if needed.
NOW MY QUESTION :P
Do I miss something? Is this there a way to clean the workspace in one go?
Now I have to remove the working sets first, then the projects by
selecting them one by one! (Perhaps I should switch the workspace as
well?).
Saturday, 31 August 2013
Mention 2 modifications that can be done to a linked list data structure so that it is converted into a binary tree data structure?
Mention 2 modifications that can be done to a linked list data structure
so that it is converted into a binary tree data structure?
It's an A level question. I looked it out on google but only programs are
found. I need theory explanation.
so that it is converted into a binary tree data structure?
It's an A level question. I looked it out on google but only programs are
found. I need theory explanation.
Multi image in one image file
Multi image in one image file
I'm fairly new in CSS web design. I found some website combine multi image
in one image file. This is an example from Amazon :
http://g-ecx.images-amazon.com/images/G/01/x-locale/personalization/amznlike/amznlike_sprite_02._V196113939_.gif
And i really want to know how to do it in the best way. Is there any tool
for combine image and get pixel position of each image to put them in CSS?
I'm fairly new in CSS web design. I found some website combine multi image
in one image file. This is an example from Amazon :
http://g-ecx.images-amazon.com/images/G/01/x-locale/personalization/amznlike/amznlike_sprite_02._V196113939_.gif
And i really want to know how to do it in the best way. Is there any tool
for combine image and get pixel position of each image to put them in CSS?
Toolbar context menu showing inside toolbarbutton's xul panel
Toolbar context menu showing inside toolbarbutton's xul panel
I have a toolbarbutton that when clicked, shows a panel. When i right
click the panel i'm getting the following:
This is the same context menu that shows when i click on the main toolbar
or even the toolbarbuttons.
The xul is:
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="testToolbarIcon"
image="chrome://myext/content/images/aicon.png"
type="panel"
class="toolbarbutton-1 chromeclass-toolbar-additional">
<panel id="testPanel"
type="arrow"
level="parent">
<vbox id="testbox" align="top" width="200" height="200">
<label value="Test Label" />
</vbox>
</panel>
</toolbarbutton>
</toolbarpalette>
Any idea on how to stop this behavior from passing to the panel?
I have a toolbarbutton that when clicked, shows a panel. When i right
click the panel i'm getting the following:
This is the same context menu that shows when i click on the main toolbar
or even the toolbarbuttons.
The xul is:
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="testToolbarIcon"
image="chrome://myext/content/images/aicon.png"
type="panel"
class="toolbarbutton-1 chromeclass-toolbar-additional">
<panel id="testPanel"
type="arrow"
level="parent">
<vbox id="testbox" align="top" width="200" height="200">
<label value="Test Label" />
</vbox>
</panel>
</toolbarbutton>
</toolbarpalette>
Any idea on how to stop this behavior from passing to the panel?
Unproject mouse to get 3D world coordinates Libgdx
Unproject mouse to get 3D world coordinates Libgdx
My Question: How do i get a 3D model to move with the mouse cursor keeping
the y location of the model at 0. (Using Libgdx)
What i have tried: I'm trying to get my 3D models to follow my cursor.
At the moment i have simply made the models move with the x and y
coordinates of my mouse with adding factors like a multiplier and camera
location. This is not very good because it doesn't follow the cursor and
if i rotate the camera then the model doesn't move in the correct
direction.
This is the code i used for moving the model :
instances.get(modelIndex).transform.setToTranslation(((Gdx.input.getX()-650)/10)
+ cam.position.x,0,((Gdx.input.getY()-400)/10)+ cam.position.z);
Here's a link to an image of the problem (The green circle is where the
mouse is). http://i.imgur.com/kFfSJQ2.png
I know that I'm going about this wrong and that i should be using the
unproject method. I have tried to use the unproject method and did have
little success, the model was just stuck to the near pane of the camera. I
want my object to stay at 0 on the y axes so i used this
cam.unproject(mousePos);
instances.get(modelIndex).transform.setToTranslation(mousePos.x, 0,
mousePos.z); This then resulted in the model moving quite slowly(not with
the mouse), in the right direction. Also when i rotated or moved the
camera the model would be set somewhere in the distance or even behind the
camera.
My Question: How do i get a 3D model to move with the mouse cursor keeping
the y location of the model at 0. (Using Libgdx)
What i have tried: I'm trying to get my 3D models to follow my cursor.
At the moment i have simply made the models move with the x and y
coordinates of my mouse with adding factors like a multiplier and camera
location. This is not very good because it doesn't follow the cursor and
if i rotate the camera then the model doesn't move in the correct
direction.
This is the code i used for moving the model :
instances.get(modelIndex).transform.setToTranslation(((Gdx.input.getX()-650)/10)
+ cam.position.x,0,((Gdx.input.getY()-400)/10)+ cam.position.z);
Here's a link to an image of the problem (The green circle is where the
mouse is). http://i.imgur.com/kFfSJQ2.png
I know that I'm going about this wrong and that i should be using the
unproject method. I have tried to use the unproject method and did have
little success, the model was just stuck to the near pane of the camera. I
want my object to stay at 0 on the y axes so i used this
cam.unproject(mousePos);
instances.get(modelIndex).transform.setToTranslation(mousePos.x, 0,
mousePos.z); This then resulted in the model moving quite slowly(not with
the mouse), in the right direction. Also when i rotated or moved the
camera the model would be set somewhere in the distance or even behind the
camera.
Subscribe to:
Comments (Atom)