Defining multiple objects based on size of two lists (python)
I am trying to find a way of creating objects based on the size of two
lists. I have to create an object for each combination of indices of the
two lists, i.e. if both lists is of the length 3, 9 new objects should be
created and defined.
The lists can be of rather large lengths and it would make the script a
lot nicer if I did not have to use an if loop to go through all possible
combinations.
A first I thought I could do the following:
for i in range(len(list1)):
for j in range(len(list2):
Name_of_Object+[i]+[j] = (object definition)
But this is not possible and I get the following error:
SyntaxError: can't assign to operator
But is there a way of creating objects based on indices of a list?
Best, Martin
(I am using the Canopy environment to do my python programming.)
Tuesday, 10 September 2013
Does any-one have a list of the permissible content elements for each SVG element?
Does any-one have a list of the permissible content elements for each SVG
element?
I am trying to build a perl hash which describes the permissible content
elements for each SVG element. Does any-one have a perl script that can do
this?
element?
I am trying to build a perl hash which describes the permissible content
elements for each SVG element. Does any-one have a perl script that can do
this?
Knockout Error: Cannot find closing comment tag to match
Knockout Error: Cannot find closing comment tag to match
This may seem like a duplicate question, but none of the other answers
have helped me. I have the following HTML (it's a Razor template, but no
Razor specifics here).
<p class="search-results-summary">
Results
<!-- ko if: SearchTerms.Query -->
for <span data-bind="html: SearchTerms.Query"></span>
<!-- /ko -->
<!-- ko if: SearchTerms.Names -->
for Names <span data-bind="html: SearchTerms.Names.join(', ')"></span>
<!-- /ko -->
<!-- ko if: SearchTerms.Location && AlternativeLocations &&
AlternativeLocations.length -->
within <span data-bind="text: SearchTerms.LocationRadio"></span>
miles of <span data-bind="html: SearchTerms.Location"></span>.
<!-- ko if: AlternativeLocations && AlternativeLocations.length >
1 -->
<a class="more alternative-locations" href="#">more</a>
<ul id="other-location-matches" data-bind="foreach:
AlternativeLocations.slice(1).sort()" style="display: none">
<li>> Did you mean <a data-bind="html: $data, attr: {
href: Edge.API.CurrentSearchResponse.SearchTerms.mutate({
Location: $data }).getUrl() }"></a>?</li>
</ul>
<!-- /ko -->
<!-- /ko -->
<!-- ko if: SearchTerms.Location && (!AlternativeLocations ||
AlternativeLocations.length == 0) -->
<span class="error">We couldn't find '<span data-bind="html:
SearchTerms.Location"></span>' on the map. Your search ran Worldwide.
</span>
<!-- /ko -->
</p>
When I try to bind this template using Knockout, I get this error:
Error: Cannot find closing comment tag to match: ko if:
SearchTerms.Location && AlternativeLocations &&
AlternativeLocations.length
I have tried:
Upgrading Knockout from 2.2.1 to 2.3.0. No use
Verifying HTML/XML structure. It's good!
Removing the <ul id="other-location-matches"...> seems to get rid of the
issue... but I need that <ul>!!
Any ideas? Am I looking at a Knockout.js bug?
This may seem like a duplicate question, but none of the other answers
have helped me. I have the following HTML (it's a Razor template, but no
Razor specifics here).
<p class="search-results-summary">
Results
<!-- ko if: SearchTerms.Query -->
for <span data-bind="html: SearchTerms.Query"></span>
<!-- /ko -->
<!-- ko if: SearchTerms.Names -->
for Names <span data-bind="html: SearchTerms.Names.join(', ')"></span>
<!-- /ko -->
<!-- ko if: SearchTerms.Location && AlternativeLocations &&
AlternativeLocations.length -->
within <span data-bind="text: SearchTerms.LocationRadio"></span>
miles of <span data-bind="html: SearchTerms.Location"></span>.
<!-- ko if: AlternativeLocations && AlternativeLocations.length >
1 -->
<a class="more alternative-locations" href="#">more</a>
<ul id="other-location-matches" data-bind="foreach:
AlternativeLocations.slice(1).sort()" style="display: none">
<li>> Did you mean <a data-bind="html: $data, attr: {
href: Edge.API.CurrentSearchResponse.SearchTerms.mutate({
Location: $data }).getUrl() }"></a>?</li>
</ul>
<!-- /ko -->
<!-- /ko -->
<!-- ko if: SearchTerms.Location && (!AlternativeLocations ||
AlternativeLocations.length == 0) -->
<span class="error">We couldn't find '<span data-bind="html:
SearchTerms.Location"></span>' on the map. Your search ran Worldwide.
</span>
<!-- /ko -->
</p>
When I try to bind this template using Knockout, I get this error:
Error: Cannot find closing comment tag to match: ko if:
SearchTerms.Location && AlternativeLocations &&
AlternativeLocations.length
I have tried:
Upgrading Knockout from 2.2.1 to 2.3.0. No use
Verifying HTML/XML structure. It's good!
Removing the <ul id="other-location-matches"...> seems to get rid of the
issue... but I need that <ul>!!
Any ideas? Am I looking at a Knockout.js bug?
How can others access my localhost folder in LAMPP?
How can others access my localhost folder in LAMPP?
I have up LAMPP server in my local machine. I want other person to access
my localhost and see the content. How can this be done ? Can it be done
using my IP address ?
I have up LAMPP server in my local machine. I want other person to access
my localhost and see the content. How can this be done ? Can it be done
using my IP address ?
ARMAX model forecasting leads to "ValueError: matrices are not aligned" when passing exog values
ARMAX model forecasting leads to "ValueError: matrices are not aligned"
when passing exog values
I'm struggling with forecasting out of sample values with an ARMAX model.
Fitting the model works fine.
armax_mod31 = sm.tsa.ARMA(endog = sales, order = (3,1), exog = media).fit()
armax_mod31.fittedvalues
Forecasting without exogenous values, as far as I have an according model,
works fine as well.
arma_mod31 = sm.tsa.ARMA(sales, (3,1)).fit()
all_arma = arma_mod31.forecast(steps = 14, alpha = 0.05)
forecast_arma = Series(res_arma[0], index = pd.date_range(start =
"2013-08-21", periods = 14))
ci_arma = DataFrame(res_arma[2], columns = ["lower", "upper"])
However as soon as I want to predict out of sample values I run into
problems.
all_armax = armax_mod31.forecast(steps = 14, alpha = 0.05, exog = media_out)
leads to "ValueError: matrices are not aligned".
My first idea was, that the length of *media_out* does not fit. I checked
it several times and tried out to pass other series as exog. Length of
exog is the same as number of steps. I tried out a time series and also
only *media_out.values*.
Checked the documentation:
"exog : array
If the model is an ARMAX, you must provide out of sample
values for the exogenous variables. This should not include
the constant."
As far as I understand this is what I do. Any ideas what I'm doing wrong?
In addition I found this ipython notebook
http://nbviewer.ipython.org/cb6e9b476a41586958b5 while looking for a
solution on the web. On In [53]: you can see a similar error. The author's
comment suggests a general problem with out-of-sample prediction, am I
right?
I'm running python 2.7.3, pandas 0.12.0-1 and statsmodels 0.5.0-1.
when passing exog values
I'm struggling with forecasting out of sample values with an ARMAX model.
Fitting the model works fine.
armax_mod31 = sm.tsa.ARMA(endog = sales, order = (3,1), exog = media).fit()
armax_mod31.fittedvalues
Forecasting without exogenous values, as far as I have an according model,
works fine as well.
arma_mod31 = sm.tsa.ARMA(sales, (3,1)).fit()
all_arma = arma_mod31.forecast(steps = 14, alpha = 0.05)
forecast_arma = Series(res_arma[0], index = pd.date_range(start =
"2013-08-21", periods = 14))
ci_arma = DataFrame(res_arma[2], columns = ["lower", "upper"])
However as soon as I want to predict out of sample values I run into
problems.
all_armax = armax_mod31.forecast(steps = 14, alpha = 0.05, exog = media_out)
leads to "ValueError: matrices are not aligned".
My first idea was, that the length of *media_out* does not fit. I checked
it several times and tried out to pass other series as exog. Length of
exog is the same as number of steps. I tried out a time series and also
only *media_out.values*.
Checked the documentation:
"exog : array
If the model is an ARMAX, you must provide out of sample
values for the exogenous variables. This should not include
the constant."
As far as I understand this is what I do. Any ideas what I'm doing wrong?
In addition I found this ipython notebook
http://nbviewer.ipython.org/cb6e9b476a41586958b5 while looking for a
solution on the web. On In [53]: you can see a similar error. The author's
comment suggests a general problem with out-of-sample prediction, am I
right?
I'm running python 2.7.3, pandas 0.12.0-1 and statsmodels 0.5.0-1.
datatable.integer64 argument is not working for me should it?
datatable.integer64 argument is not working for me should it?
I am trying to load integer64 as character in fread ?fread indicates that
the integer64 argument is not implemented but the
options(datatable.integer64) is. Though fread keeps loading as int64.
How can I tell fread to load as character. If colClasses is the answer, I
think it does not allow to specify a single column name or index and the
table I load has tens of columns so unpracticable...
Here is a sample
#for int 64
library(bit64)
#for fast everything
library(data.table)
#here is a sample
df <- structure(list(IDFD = structure(c(5.13878419797985e-299,
5.13878419797985e-299,
+ 5.13878419797985e-299, 5.13878419797987e-299, 5.13878419797987e-299,
+ 5.13878419797987e-299, 5.13878419797987e-299, 5.13878419797987e-299,
+ 5.13878419797988e-299, 5.13878419797988e-299), class = "integer64")),
.Names = "IDFD", row.names = c(NA,
+ -10L), class = c("data.table", "data.frame"))
#write the sample to file
write.csv(df,"test.csv",quote=F,row.names=F)
#I can't load it as characters
options(datatable.integer64='character')
str(fread("test.csv",integer64='character'))
Classes 'data.table' and 'data.frame': 10 obs. of 1 variable:
$ IDFD:Class 'integer64' num [1:10] 5.14e-299 5.14e-299 5.14e-299
5.14e-299 5.14e-299 ...
I am trying to load integer64 as character in fread ?fread indicates that
the integer64 argument is not implemented but the
options(datatable.integer64) is. Though fread keeps loading as int64.
How can I tell fread to load as character. If colClasses is the answer, I
think it does not allow to specify a single column name or index and the
table I load has tens of columns so unpracticable...
Here is a sample
#for int 64
library(bit64)
#for fast everything
library(data.table)
#here is a sample
df <- structure(list(IDFD = structure(c(5.13878419797985e-299,
5.13878419797985e-299,
+ 5.13878419797985e-299, 5.13878419797987e-299, 5.13878419797987e-299,
+ 5.13878419797987e-299, 5.13878419797987e-299, 5.13878419797987e-299,
+ 5.13878419797988e-299, 5.13878419797988e-299), class = "integer64")),
.Names = "IDFD", row.names = c(NA,
+ -10L), class = c("data.table", "data.frame"))
#write the sample to file
write.csv(df,"test.csv",quote=F,row.names=F)
#I can't load it as characters
options(datatable.integer64='character')
str(fread("test.csv",integer64='character'))
Classes 'data.table' and 'data.frame': 10 obs. of 1 variable:
$ IDFD:Class 'integer64' num [1:10] 5.14e-299 5.14e-299 5.14e-299
5.14e-299 5.14e-299 ...
How to make this method reusable?
How to make this method reusable?
I have copy pasted this method into two classes. I would rather reuse it
from the first class. This is in a windows forms application.
public void defineMapArea()
{
PictureBox pictureBox1 = new PictureBox();
// Dock the PictureBox to the form and set its background to white.
pictureBox1.Dock = DockStyle.Fill;
pictureBox1.BackColor = Color.White;
// Connect the Paint event of the PictureBox to the event handler method.
pictureBox1.Paint += new
System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
// Add the PictureBox control to the Form.
this.Controls.Add(pictureBox1);
}
The only thing that needs to change in the method from one class to
another is the "this" keyword which refers to the class, as hovering over
"this" confirms. I thought maybe "this" will just apply to the class
calling the method, but i think it still refers to the class that the
method is defined in. It would be fantastic to simply pass a class as a
parameter, but i'm thinking that doesn't work as i have attempted that.
Any help appreciated. Thanks!
I have copy pasted this method into two classes. I would rather reuse it
from the first class. This is in a windows forms application.
public void defineMapArea()
{
PictureBox pictureBox1 = new PictureBox();
// Dock the PictureBox to the form and set its background to white.
pictureBox1.Dock = DockStyle.Fill;
pictureBox1.BackColor = Color.White;
// Connect the Paint event of the PictureBox to the event handler method.
pictureBox1.Paint += new
System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
// Add the PictureBox control to the Form.
this.Controls.Add(pictureBox1);
}
The only thing that needs to change in the method from one class to
another is the "this" keyword which refers to the class, as hovering over
"this" confirms. I thought maybe "this" will just apply to the class
calling the method, but i think it still refers to the class that the
method is defined in. It would be fantastic to simply pass a class as a
parameter, but i'm thinking that doesn't work as i have attempted that.
Any help appreciated. Thanks!
Subscribe to:
Posts (Atom)