Discussion:
modifying a table column
Oleksandr Huziy
2013-08-27 16:44:29 UTC
Permalink
Hi All:

I have a huge table imported from other binary files to hdf, and I forgot
to multiply the data by a factor in one case. Is there an easy way to
multiply a column by a constant factor using pytables?
To modify it in place?

Thank you

--
Sasha
Anthony Scopatz
2013-08-27 18:37:39 UTC
Permalink
Hey Sasha,

You probably want to look at the Expr class [1] where you set "out" to be
the same as the original array.

Be Well
Anthony

1. http://pytables.github.io/usersguide/libref/expr_class.html
Post by Oleksandr Huziy
I have a huge table imported from other binary files to hdf, and I forgot
to multiply the data by a factor in one case. Is there an easy way to
multiply a column by a constant factor using pytables?
To modify it in place?
Thank you
--
Sasha
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
Oleksandr Huziy
2013-08-27 19:43:58 UTC
Permalink
Thank you Anthony.

Cheers
Post by Anthony Scopatz
Hey Sasha,
You probably want to look at the Expr class [1] where you set "out" to be
the same as the original array.
Be Well
Anthony
1. http://pytables.github.io/usersguide/libref/expr_class.html
Post by Oleksandr Huziy
I have a huge table imported from other binary files to hdf, and I forgot
to multiply the data by a factor in one case. Is there an easy way to
multiply a column by a constant factor using pytables?
To modify it in place?
Thank you
--
Sasha
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
Oleksandr Huziy
2013-08-27 23:50:34 UTC
Permalink
Post by Anthony Scopatz
Hey Sasha,
You probably want to look at the Expr class [1] where you set "out" to be
the same as the original array.
Be Well
Anthony
1. http://pytables.github.io/usersguide/libref/expr_class.html
I just wanted to make sure if it is possible to use an assignment in
expressions? (this gives me a syntax error exception, complains about the
equal sign in the expression)

h = tb.open_file(path, mode="a")
varTable = h.get_node("/", var_name)
coef = 3 * 60 * 60 #output step
expr = tb.Expr("c = c * m", uservars = {"c": varTable.cols.field, "m":
coef })
expr.eval()
varTable.flush()
h.close()

Is this an optimal way of multiplying a column? (this one works, but I
think it loads all the data into memory...right?)

expr = tb.Expr("c * m", uservars = {"c": varTable.cols.field, "m": coef
})
varTable.cols.field[:] = expr.eval()

Thank you

Cheers
Post by Anthony Scopatz
Post by Oleksandr Huziy
I have a huge table imported from other binary files to hdf, and I forgot
to multiply the data by a factor in one case. Is there an easy way to
multiply a column by a constant factor using pytables?
To modify it in place?
Thank you
--
Sasha
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
Anthony Scopatz
2013-08-27 23:58:12 UTC
Permalink
Post by Oleksandr Huziy
Post by Anthony Scopatz
Hey Sasha,
You probably want to look at the Expr class [1] where you set "out" to be
the same as the original array.
Be Well
Anthony
1. http://pytables.github.io/usersguide/libref/expr_class.html
I just wanted to make sure if it is possible to use an assignment in
expressions? (this gives me a syntax error exception, complains about the
equal sign in the expression)
Hi Sasha,

Assignment is a statement not an expression, so it is not possible to use
here. This is why you are getting a syntax error.
Post by Oleksandr Huziy
h = tb.open_file(path, mode="a")
varTable = h.get_node("/", var_name)
coef = 3 * 60 * 60 #output step
coef })
expr.eval()
varTable.flush()
h.close()
Is this an optimal way of multiplying a column? (this one works, but I
think it loads all the data into memory...right?)
coef })
varTable.cols.field[:] = expr.eval()
You are right that this loads the entire computed array into memory and is
therefore not optimal. I would do something like the following:

h = tb.open_file(path, mode="a")
varTable = h.get_node("/", var_name)
coef = 3 * 60 * 60 #output step
c = varTable.cols.field
expr = tb.Expr("c = c * m", uservars = {"c": c, "m": coef })
expr.set_output(c)
expr.eval()
varTable.flush()
h.close()

Be Well
Anthony
Post by Oleksandr Huziy
Thank you
Cheers
Post by Anthony Scopatz
Post by Oleksandr Huziy
I have a huge table imported from other binary files to hdf, and I
forgot to multiply the data by a factor in one case. Is there an easy way
to multiply a column by a constant factor using pytables?
To modify it in place?
Thank you
--
Sasha
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
Oleksandr Huziy
2013-08-28 00:44:57 UTC
Permalink
Post by Anthony Scopatz
You are right that this loads the entire computed array into memory and is
h = tb.open_file(path, mode="a")
varTable = h.get_node("/", var_name)
coef = 3 * 60 * 60 #output step
c = varTable.cols.field
expr = tb.Expr("c * m", uservars = {"c": c, "m": coef })
expr.set_output(c)
expr.eval()
varTable.flush()
h.close()
Aha, this is cool. Thanks Anthony.

Cheers
--
Sasha
Post by Anthony Scopatz
Post by Oleksandr Huziy
On Tue, Aug 27, 2013 at 11:44 AM, Oleksandr Huziy <
Post by Oleksandr Huziy
I have a huge table imported from other binary files to hdf, and I
forgot to multiply the data by a factor in one case. Is there an easy way
to multiply a column by a constant factor using pytables?
To modify it in place?
Thank you
--
Sasha
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
Anthony Scopatz
2013-08-28 00:51:32 UTC
Permalink
Glad I could help!
Post by Oleksandr Huziy
Post by Anthony Scopatz
You are right that this loads the entire computed array into memory and
h = tb.open_file(path, mode="a")
varTable = h.get_node("/", var_name)
coef = 3 * 60 * 60 #output step
c = varTable.cols.field
expr = tb.Expr("c * m", uservars = {"c": c, "m": coef })
expr.set_output(c)
expr.eval()
varTable.flush()
h.close()
Aha, this is cool. Thanks Anthony.
Cheers
--
Sasha
Post by Anthony Scopatz
Post by Oleksandr Huziy
On Tue, Aug 27, 2013 at 11:44 AM, Oleksandr Huziy <
Post by Oleksandr Huziy
I have a huge table imported from other binary files to hdf, and I
forgot to multiply the data by a factor in one case. Is there an easy way
to multiply a column by a constant factor using pytables?
To modify it in place?
Thank you
--
Sasha
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Pytables-users mailing list
https://lists.sourceforge.net/lists/listinfo/pytables-users
Continue reading on narkive:
Loading...