Title: Document the use of jarray and array better with respect to zeros function
Type: Severity: normal
Components: Documentation Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alex, amak, fwierzbicki, gmseed, juneau001, zyasoft
Priority: normal Keywords:

Created on 2011-06-10.13:29:03 by gmseed, last changed 2016-01-06.18:55:27 by zyasoft.

msg6548 (view) Author: Graham Seed (gmseed) Date: 2011-06-10.13:29:03
The Jython documentation on your website states:

"The array module exports two factory functions:

array(type, sequence)
zeros(type, length)"

If I type:
arr = zeros('i',10)
I get the error:
'zeros' is not defined

Chapter 2 of the Jython book linked-to on your website at:

states in Listing 2-30:

arr2 = zeros(6, 'i')

noting that the ordering of the type and length are reversed. Using this ordering doesn't work either.

Thus, as a new user I am left wondering which way round the type and length are and whether this function is supported at all.
msg6621 (view) Author: A. Fox (alex) Date: 2011-08-29.13:59:37
The confusion seems to stem from the fact that jarray and array are different modules. Both are working.

>>> from array import zeros
>>> zeros('i',10)
array('i', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

>>> from jarray import zeros
>>> zeros(10, 'i')
array('i', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
msg6696 (view) Author: Alan Kennedy (amak) Date: 2011-11-02.23:31:00
I don't see an issue here. It is implicit from code listing 2-28 and from the descriptive text that the zeros method is in the jarray module: "Another useful feature of the jarray is that we can create empty arrays if we wish by using the zeros() method."

I think this issue should be closed as "rejected".
msg6836 (view) Author: Alan Kennedy (amak) Date: 2012-03-19.19:10:45
Assigning to Josh: he should decide if the book needs to clearer on this matter.
msg8374 (view) Author: Juneau001 (juneau001) Date: 2014-05-10.14:48:01
Listing 2-29 and 2-30 seem to be incorrect, as zeros is being invoked with the parameters backwards.  I will need to patch this documentation to repair these two examples.
msg10590 (view) Author: Jim Baker (zyasoft) Date: 2016-01-06.18:51:07
It's worth noting the following:

The jarray module is mostly phased out, but it is still has one
constructor function - zeros - that is not directly available in the
array module.

The equivalent of
jarray.zeros(n, typecode)
array.array(typecode, itertools.repeat(0, n))

however itertools.repeat does not define __len__ and therefore we
have to first build out the zero sequence separately, then copy
over. This overhead could be significant for large arrays.
msg10591 (view) Author: Jim Baker (zyasoft) Date: 2016-01-06.18:54:58
Also I should point out that the Jython book is available at

and is currently being built at

So any PRs that are merged into the above repo will automatically get built out. We should do that.

Note there is at least one chapter ( where we are using RST that is not buildable via RTD. That should be a simple fix too.
Date User Action Args
2016-01-06 18:55:27zyasoftsetassignee: juneau001 ->
2016-01-06 18:54:58zyasoftsetmessages: + msg10591
2016-01-06 18:51:08zyasoftsetnosy: + zyasoft
messages: + msg10590
2014-05-10 14:48:02juneau001setpriority: normal
messages: + msg8374
2014-05-04 20:34:13zyasoftsettitle: array and zeros -> Document the use of jarray and array better with respect to zeros function
2013-02-26 18:00:14fwierzbickisetnosy: + fwierzbicki
2012-03-19 19:10:45amaksetassignee: juneau001
messages: + msg6836
nosy: + juneau001
2011-11-02 23:31:00amaksetnosy: + amak
messages: + msg6696
2011-08-29 13:59:37alexsetnosy: + alex
messages: + msg6621
2011-06-10 13:29:03gmseedcreate