github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/mat/matrix_example_test.go (about)

     1  // Copyright ©2019 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mat_test
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/jingcheng-WU/gonum/mat"
    11  )
    12  
    13  func ExampleCol() {
    14  	// This example copies the second column of a matrix into col, allocating a new slice of float64.
    15  	m := mat.NewDense(3, 3, []float64{
    16  		2.0, 9.0, 3.0,
    17  		4.5, 6.7, 8.0,
    18  		1.2, 3.0, 6.0,
    19  	})
    20  
    21  	col := mat.Col(nil, 1, m)
    22  
    23  	fmt.Printf("col = %#v", col)
    24  	// Output:
    25  	//
    26  	// col = []float64{9, 6.7, 3}
    27  }
    28  
    29  func ExampleRow() {
    30  	// This example copies the third row of a matrix into row, allocating a new slice of float64.
    31  	m := mat.NewDense(3, 3, []float64{
    32  		2.0, 9.0, 3.0,
    33  		4.5, 6.7, 8.0,
    34  		1.2, 3.0, 6.0,
    35  	})
    36  
    37  	row := mat.Row(nil, 2, m)
    38  
    39  	fmt.Printf("row = %#v", row)
    40  	// Output:
    41  	//
    42  	// row = []float64{1.2, 3, 6}
    43  }