~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to doc/manual/arrays.rst

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-11-17 19:32:52 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20131117193252-tkrpclguqqebqa35
Tags: 0.2.0+dfsg-3
testsuite-i386.patch: loosen the numerical precision for yet another test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
                                      specified element type
81
81
``rand(dims)``                        ``Array`` of ``Float64``\ s with random, iid[#]_ and uniformly
82
82
                                      distributed values in [0,1)
83
 
``randf(dims)``                       ``Array`` of ``Float32``\ s with random, iid and uniformly
84
 
                                      distributed values in [0,1)
85
83
``randn(dims)``                       ``Array`` of ``Float64``\ s with random, iid and standard normally
86
84
                                      distributed random values
87
85
``eye(n)``                            ``n``-by-``n`` identity matrix
174
172
``(i_1, i_2, ..., i_n)`` of X containing the value
175
173
``A[I_1[i_1], I_2[i_2], ..., I_n[i_n]]``. Trailing dimensions indexed with
176
174
scalars are dropped. For example, the dimensions of ``A[I, 1]`` will be
177
 
``(length(I),)``. The size of a dimension indexed by a boolean vector
178
 
will be the number of true values in the vector (they behave as if they were
179
 
transformed with ``find``).
 
175
``(length(I),)``. Boolean vectors are first transformed with ``find``; the size of
 
176
a dimension indexed by a boolean vector will be the number of true values in the vector.
180
177
 
181
178
Indexing syntax is equivalent to a call to ``getindex``::
182
179
 
210
207
3. An arbitrary integer vector, including the empty vector ``[]``
211
208
4. A boolean vector
212
209
 
213
 
The size of X should be ``(length(I_1), length(I_2), ..., length(I_n))``, and
214
 
the value in location ``(i_1, i_2, ..., i_n)`` of A is overwritten with
215
 
the value ``X[I_1[i_1], I_2[i_2], ..., I_n[i_n]]``.
 
210
If ``X`` is an array, its size must be ``(length(I_1), length(I_2), ..., length(I_n))``,
 
211
and the value in location ``i_1, i_2, ..., i_n`` of ``A`` is overwritten with
 
212
the value ``X[I_1[i_1], I_2[i_2], ..., I_n[i_n]]``. If ``X`` is not an array, its
 
213
value is written to all referenced locations of ``A``.
 
214
 
 
215
A boolean vector used as an index behaves as in ``getindex`` (it is first transformed
 
216
with ``find``).
216
217
 
217
218
Index assignment syntax is equivalent to a call to ``setindex!``::
218
219
 
278
279
    abs abs2 angle cbrt
279
280
    airy airyai airyaiprime airybi airybiprime airyprime
280
281
    acos acosh asin asinh atan atan2 atanh
 
282
    acsc acsch asec asech acot acoth
281
283
    cos  cosh  sin  sinh  tan  tanh  sinc  cosc
 
284
    csc  csch  sec  sech  cot  coth
 
285
    acosd asind atand asecd acscd acotd
 
286
    cosd  sind  tand  secd  cscd  cotd
282
287
    besselh besseli besselj besselj0 besselj1 besselk bessely bessely0 bessely1
283
 
    exp  erf  erfc  exp2  expm1
 
288
    exp  erf  erfc  erfinv erfcinv exp2  expm1
284
289
    beta dawson digamma erfcx erfi
285
290
    exponent eta zeta gamma
286
291
    hankelh1 hankelh2
299
304
the name of the function to vectorize. Here is a simple example::
300
305
 
301
306
    julia> square(x) = x^2
302
 
    # methods for generic function square
303
 
    square(x) at none:1
304
 
    
 
307
    square (generic function with 1 method)
 
308
 
305
309
    julia> @vectorize_1arg Number square
306
 
    # methods for generic function square
307
 
    square{T<:Number}(x::AbstractArray{T<:Number,1}) at operators.jl:216
308
 
    square{T<:Number}(x::AbstractArray{T<:Number,2}) at operators.jl:217
309
 
    square{T<:Number}(x::AbstractArray{T<:Number,N}) at operators.jl:219
 
310
    square (generic function with 4 methods)
 
311
 
 
312
    julia> methods(square)
 
313
    # 4 methods for generic function "square":
 
314
    square{T<:Number}(x::AbstractArray{T<:Number,1}) at operators.jl:236
 
315
    square{T<:Number}(x::AbstractArray{T<:Number,2}) at operators.jl:237
 
316
    square{T<:Number}(x::AbstractArray{T<:Number,N}) at operators.jl:239
310
317
    square(x) at none:1
311
 
    
 
318
 
312
319
    julia> square([1 2 4; 5 6 7])
313
 
    2x3 Int64 Array:
 
320
    2x3 Array{Int64,2}:
314
321
      1   4  16
315
322
     25  36  49
316
323