473,881 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling J from Python

It is quite easy to call J from Python

http://groups.google.com/group/J-Pro...84b75667f5f64e

Feb 5 '07
50 2935
Larry Bates a écrit :
>
def avg(l):
return float(sum(l))/len(l)

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

2.5
def avg(*args):
return float(sum(args) ) / len(args))
>
Which can actually be read and debugged in the future!
in_my_arms(tm)
Feb 5 '07 #21
Bjoern Schliessmann <us************ **************@ spamgourmet.com 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 "ambivalenc e"[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).
Feb 5 '07 #22
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.
Feb 5 '07 #23
Bruno Desthuilliers wrote:
Gosi a écrit :
>On Feb 5, 2:59 pm, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
J has very many advanced operations.

what's an "advanced operation" ?
An operation which dont stay in place.

Feb 5 '07 #24
Alexander Schmolck a écrit :
Bjoern Schliessmann <us************ **************@ spamgourmet.com 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?
No, thanks. But hopefully we have Python :

Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on
linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>3 + 4
7
>>>
!-)
Feb 5 '07 #25
Laurent Pointal a écrit :
Bruno Desthuilliers wrote:

>>Gosi a écrit :
>>>On Feb 5, 2:59 pm, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
J has very many advanced operations.

what's an "advanced operation" ?


An operation which dont stay in place.
You meant something like a good camembert ?-)
Feb 5 '07 #26
Bruno Desthuilliers <bd************ *****@free.quel quepart.frwrite s:
No, thanks. But hopefully we have Python :

Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on linux2

Type "help", "copyright" , "credits" or "license" for more information.
>>3 + 4
7
>>>
My calculuator even gives a pretty good answer if I divide them (without
importing anything from the __future__).

'as

Feb 5 '07 #27
Alexander Schmolck wrote:
For example I once wrote this (slow) code to display
part of a mandelbrot fractal:

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

It'll likely require you more typing in python,
Yes, but with Python you wouldn't have to spend a
couple of weeks sitting and thinking before starting
to type that line...

--
Greg
Feb 6 '07 #28
On Feb 5, 8:48 am, "Gosi" <gos...@gmail.c omwrote:
It is quite easy to call J from Python

http://groups.google.com/group/J-Pro...ead/thread/5e8...
There are a couple of issue that should be adressed. Am I going to
jail if I write a program and then redistribute all the files required
to run the program I write?? The second is how do I use the j stuff
without learning all that much about j. I am just intrested in
stealing graphics libraries and using what I have already written in
python..

Feb 6 '07 #29
On Feb 5, 2:48 pm, "Gosi" <gos...@gmail.c omwrote:
It is quite easy to call J from Python

http://groups.google.com/group/J-Pro...ead/thread/5e8...
Hii Gosi,
>From reading what has gone before, you seem to have got it in the neck
from some pythonistas.
I'd just like to say from some but not all.

It is *A GOOD THING* that Python has bridges to other languages. Some
may not care to program in the other language - which is a separate
concer;. but a link between the language - be it Haskell or befunge or
J, makes Python better in my view. If your expert J programmers have
need for something that is hard to do in J they might now be more
likely to use Python.

We should remember that Python is a great glue language too, and links
to other languages and tools is how we maintain that position.

- Paddy.

Feb 6 '07 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1648
by: Bill Orcutt | last post by:
Having seen the number of lost souls asking questions about embedding Python in the archives of this group, I hesitate to add myself to their number, but I've hit a problem I can't quite get my head around. I have a simple C program that embeds a python interpreter to execute python commands and return stdout, and to a point everything works as intended. The problem that each command seems to be executed in its own context and knows...
0
2330
by: Natsu Mizutani | last post by:
Hello, I'm trying to wrap a c++ library using MPI inside with boost.python (or SWIG). I managed to find that calling `MPI::Init()` embeded in a c++ funtion would not work. So, I decided to use `pyMPI`. To avoid overhead of pickling and unpickling while calling `mpi.send` in Python, I'd rather call c++ functions `MPI::Isend()` etc. embeded in a c++ function.
2
2405
by: Satish Chimakurthi | last post by:
Hi all, My question is surely a basic one, but somehow, I am not able to figure it out. I have a python file "satish.py" as follows: *satish.py* def main(): y()
9
3776
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so funny, at least for me. I guess dev'ing a GUI in a test-driven way is not possible, or is it? I'm using wxPython, so if anyone has an idea... For now most of the time I extend and change the gui things, then run it, do the clicks to go thru the...
11
9114
by: Kamilche | last post by:
What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following: MyFunc instead of:
1
1588
by: Stephen Kellett | last post by:
Hello everyone, I'm trying to do something in C calling Python and its failing. I'd be grateful if you could take a look and hopefully you have an answer. What I'm trying to do is determine the address of the "collect" function in the "gc" module. I want to do this so that we can determine when a garbage collection happens, regardless of how it is triggered (explicitly by a user call, or implicitly by the behaviour of the program...
1
1930
by: Gerald Klix | last post by:
I read the whol email thread carefully and could not find any sentence by Guido, which states that he does not accept ctypes for the standard library. He just declined to rewrite winreg. Did I miss something? Cya, Gerald -----Ursprüngliche Nachricht----- Von: python-list-bounces+gerald.klix=klix.ch@python.org Im Auftrag von
10
13316
by: Finger.Octopus | last post by:
Hello, I have been trying to call the super constructor from my derived class but its not working as expected. See the code: class HTMLMain: def __init__(self): self.text = "<HTML><BODY>"; print(self.text); def __del__(self): self.text = "</BODY></HTML>"; print(self.text);
47
5004
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both and my c++ code should call c code.but when i tried to call a function in c code externing that function in my c++ code, i am getting unresolved external symbol error. Whatever i try its giving more and more errrors...so is it possible to merge 2...
16
3793
by: Jaco Naude | last post by:
Hi there, This is my first post over here and I hope someone can give me some guidance. I'm trying to embed Python into a Visual C++ 2008 application and I'm getting linker problems. I've compiled a DLL of the Python source code using the pythoncode VC++ project in the PCbuild folder of the source download and this works 100% without any warnings etc. I've done this in Debug and Release mode without any problems.
0
9928
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10401
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7953
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.