Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Calling J from Python

Reply
Thread Tools

Calling J from Python

 
 
Alexander Schmolck
Guest
Posts: n/a
 
      02-05-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> Gosi> J is in many ways similar to Python.
>
> Gosi> J has very many advanced operations.
>
> Gosi> http://www.jsoftware.com/
>
> Doesn't look like open source of any variety. If a person uses Python with
> various add-ons (RPy, numpy, matplotlib, etc) why would they want to switch
> to a closed source product?


You wouldn't, if for nothing else because python has far better scientific
libraries. If you've got an interest in programming languages as such J (or
some other APL) is worth a look though; it's also handy for quick mathematical
experimentation (J's array primitives are more expressive than what numpy
offers and python doesn't support rationals, so it's not just concise due to
perl-style crypticness). For example I once wrote this (slow) code to display
part of a mandelbrot fractal:

load'viewmat'
viewmat+/2&>((j.~/~(%~i99)&+@:*^i.32)0

It'll likely require you more typing in python, but then you'd need to do such
things quite a lot for seeing an amortization in terms of less time spent with
your PC; I think most people will find they need a seizable learning
investment to get anywhere with J and python already is very expressive for
the kind of things J is good at.

'as

 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      02-05-2007
Bjoern Schliessmann wrote:
> Gosi wrote:
>
>> J is in many ways similar to Python.

>
> The only one I see at the moment is that they're both some kind of
> programming languages.
>
>> J has very many advanced operations.

>
> Sure.
>
> Mh, just looking at some "advanced" J source taken from
> wikipedia.org makes me feel sick:
>
> | Here's a J program to calculate the average of a list of numbers:
> | avg=: +/ % #
> | avg 1 2 3 4
> | 2.5
>
> In the meantime, do you now have an answer to why we should care?
>
> Regards,
>
>
> Björn
>

And why is that superior to this:

def avg(l):
return float(sum(l))/len(l)

>>>avg([1,2,3,4])

2.5


Which can actually be read and debugged in the future!

-Larry
 
Reply With Quote
 
 
 
 
Robin Becker
Guest
Posts: n/a
 
      02-05-2007
Dennis Lee Bieber wrote:
> On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
> <(E-Mail Removed)> declaimed the following
> in comp.lang.python:
>
>> Mh, just looking at some "advanced" J source taken from
>> wikipedia.org makes me feel sick:
>>
>> | Here's a J program to calculate the average of a list of numbers:
>> | avg=: +/ % #
>> | avg 1 2 3 4
>> | 2.5
>>

> That looks like some variation of APL


my colleague informs me that it is indeed associated with some of the same
people if not with Mr Iverson.
--
Robin Becker

 
Reply With Quote
 
Alexander Schmolck
Guest
Posts: n/a
 
      02-05-2007
Robin Becker <(E-Mail Removed)> writes:

> Dennis Lee Bieber wrote:
> > On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
> > <(E-Mail Removed)> declaimed the following
> > in comp.lang.python:
> >

>
> >> Mh, just looking at some "advanced" J source taken from
> >> wikipedia.org makes me feel sick:
> >>
> >> | Here's a J program to calculate the average of a list of numbers:
> >> | avg=: +/ % #
> >> | avg 1 2 3 4
> >> | 2.5
> >>

> > That looks like some variation of APL

>
> my colleague informs me that it is indeed associated with some of the same
> people if not with Mr Iverson.


The late Ken Iverson designed both J and APL (he has also written an number of
freely downloadable math books using J, see jsoftware.com).

'as

 
Reply With Quote
 
Alexander Schmolck
Guest
Posts: n/a
 
      02-05-2007
Larry Bates <(E-Mail Removed)> writes:

> And why is that superior to this:
>
> def avg(l):
> return float(sum(l))/len(l)
>
> >>>avg([1,2,3,4])

> 2.5


Apart from being less to type and it is superior in that it's generalizes much
better, e.g:

avg&.^. NB. geomtric mean
avg&.% NB. harmonic mean
avg M NB. column mean of matrix M
avg"1 M NB. row mean of matrix M

'as

 
Reply With Quote
 
Laurent Pointal
Guest
Posts: n/a
 
      02-05-2007
Diez B. Roggisch wrote:

> m =: >@(0&{)
> v =: >@(1&{)
> h =: >@(2&{)
> qu =: >@(3&{)
> z =: i.@0:
> ret =: |.@}:
> init =: z;z;z;i.
> f1m =: (m,{.@qu);v;h;}.@qu
> f5m =: (z;(v,{:@m);h;qu,ret@m) @ (f1m^:5)
> f1h =: (z;z;(h,{:@v);(qu,ret@v)) @ (f5m^:12)
> f12h =: (z;z;z;qu,ret@h,{:@h) @ (f1h^:12)
> perm =: qu @ f12h @ init
> ord =: *./ @ (#&>"_) @ C.
> days =: -: @ ord @ perm
>
>
> http://www.jsoftware.com/jwiki/Essay..._Clock_Problem
>
>
> Diez


Why dont they call it "smiley" ?

Operators: ) :-$ *<¦:O) XD -_- +_+ ^_^ *_* !_!
>_< =_= o_o X_X -_o $_$ <_< >_> o_0
><_>< ?_? '_' O.O $.$ T.T ._. u.u >-<" =] {-_-}



(source: http://en.wikipedia.org/wiki/Smiley )


 
Reply With Quote
 
Bjoern Schliessmann
Guest
Posts: n/a
 
      02-05-2007
Alexander Schmolck wrote:

> Apart from being less to type


Cool. Less to type.

> and it is superior in that it's
> generalizes much better, e.g:
>
> avg&.^. NB. geomtric mean
> avg&.% NB. harmonic mean
> avg M NB. column mean of matrix M
> avg"1 M NB. row mean of matrix M


Is there any regularity in this? If it is, it's not obvious at all.

Regards,


Björn

--
BOFH excuse #78:

Yes, yes, its called a design limitation

 
Reply With Quote
 
Stef Mientki
Guest
Posts: n/a
 
      02-05-2007
>
> Mh, just looking at some "advanced" J source taken from
> wikipedia.org makes me feel sick:
>
> | Here's a J program to calculate the average of a list of numbers:
> | avg=: +/ % #
> | avg 1 2 3 4
> | 2.5
>

And here is the Python way of calculating the average
>>> mean([1,2,3,4])

2.5

sorry, I don't see any advantage.

cheers,
Stef Mientki
 
Reply With Quote
 
Alexander Schmolck
Guest
Posts: n/a
 
      02-05-2007
Bjoern Schliessmann <(E-Mail Removed)> writes:

> Alexander Schmolck wrote:
>
> > Apart from being less to type

>
> Cool. Less to type.


Yes. Readability is more important in many context, but for something designed
for interactive experimentation and exploration little typing is absolutely
essential. Would you use a calculator that would require Java-style
boilerplate to add two numbers?

I'd also venture that readability and typing ease are typically closely
positively correlated (compare python to C++) and although I would not claim
that J is particularly readable I'm also not an expert user (I doubt I would
even then, but I'm sure it *does* make a difference).

> > and it is superior in that it's
> > generalizes much better, e.g:
> >
> > avg&.^. NB. geomtric mean
> > avg&.% NB. harmonic mean
> > avg M NB. column mean of matrix M
> > avg"1 M NB. row mean of matrix M

>
> Is there any regularity in this? If it is, it's not obvious at all.


Sure. ``f&.g`` is like ``(f o g) o g^-1`` in common mathemetical notation.
``^.`` is log and ``%`` is inversion/division. Making ``&.`` (it's called
"under") available as a convenient abstraction is IMO one really useful
innovation of J.

As for the remaing two: it's similar to numpy in that one and the same
function can normally operate on arrays of different dimensions (including
scalars). In numpy you'd also write stuff like ``mean(M, axis=1)``, it's not
exactly the same, although the axis abstraction comes from APL (another cool
idea), J introduces a slightly different approach. The ``"1`` means "operate
on cells of rank 1" (i.e. vectors), rather than "operate along a certain
axis". For dyadic (2-argument) functions you can also specify different left
and right rank, so you could write the outerproduct v'w thus: ``v *"0 1 w``
(multiply each 0-cell (i.e scalar) of v with each 1-cell (i.e. vector, there
is only one) of w). Unlike the linear algebra notation this readily
generalizes to more than 1 dimensional objects.

BTW I don't think J is an ideal language, not even for numerical computing --
there are plenty of things I'd do differently and that includes measures that
would IMO greatly aid readability (like getting rid of "ambivalence"[1]). But
I have little doubt that, no matter what its flaws may be, APL (and J is
really just an updated, ASCII-based APL) is one of the most innovative and
important programming languages ever conceived. Anyone interested in the
design of programming language for scientific computing ought to take a look
at at least a look at it or one of its descendants.

'as

Footnotes:
[1] Basically almost every J function has a completely different meaning
depending on whether you use it as a unary or binary function (just as
conventionally "-" is abusively used for both substraction and negation).
 
Reply With Quote
 
John Salerno
Guest
Posts: n/a
 
      02-05-2007
Alexander Schmolck wrote:

> Would you use a calculator that would require Java-style
> boilerplate to add two numbers?


This isn't a Java newsgroup, so your metaphor is irrelevant. People use
Python because it *isn't* Java and does not succumb to the problem you
seem to be accusing it of.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ calling java calling c++ ... Klaus Friese C++ 7 08-15-2005 09:23 PM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= ASP .Net 1 09-28-2004 12:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier ASP .Net 4 07-29-2004 01:06 PM



Advertisments