Julia 1.0 Programming by Ivo Balbaert

Julia 1.0 Programming by Ivo Balbaert

Author:Ivo Balbaert
Language: eng
Format: epub
Tags: COM051010 - COMPUTERS / Programming Languages / General, COM018000 - COMPUTERS / Data Processing, COM051440 - COMPUTERS / Software Development and Engineering / Tools
Publisher: Packt Publishing
Published: 2018-09-21T06:15:44+00:00


There is an even simpler literal notation: to concatenate two matrices a and b with the same number of rows to a matrix c, just execute c = [a b]. now b is appended to the right of a. To put b beneath c, use c = [a; b]. The following is a concrete example, a = [1 2; 3 4]and b = [5 6; 7 8]:

a

b

c = [a b]

c = [a; b]

1 2

3 4

5 6

7 8

1 2 5 6

3 4 7 8

1 2

3 4

5 6

7 8

The reshape function changes the dimensions of a matrix to new values if this is possible, for example:

reshape(1:12, 3, 4) #> returns a 3x4 array with the values 1 to 12 3x4 Array{Int64,2}: 1 4 7 10 2 5 8 11 3 6 9 12 a = rand(3, 3) #> produces a 3x3 Array{Float64,2} 3x3 Array{Float64,2}: 0.332401 0.499608 0.355623 0.0933291 0.132798 0.967591 0.722452 0.932347 0.809577 reshape(a, (9,1)) #> produces a 9x1 Array{Float64,2}: 9x1 Array{Float64,2}: 0.332401 0.0933291 0.722452 0.499608 0.132798 0.932347 0.355623 0.967591 0.809577 reshape(a, (2,2)) #> does not succeed: ERROR: DimensionMismatch("new dimensions (2,2) must be consistent

with array size 9")

When working with arrays that contain arrays, it is important to realize that such an array contains references to the contained arrays, not their values. If you want to make a copy of an array, you can use the copy() function, but this produces only a shallow copy with references to the contained arrays. In order to make a complete copy of the values, we need to use the deepcopy() function.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.