matrix

package
v0.0.0-...-d6e8a04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package matrix provide function and methods for matrix operations Matrix operations are done on float arrays

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	//ErrOutOfRange your basic index out of range error
	ErrOutOfRange = errors.New("Out of Range")
)

Functions

This section is empty.

Types

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

Matrix represents matrix object

func Indentiy

func Indentiy(order int) *Matrix

Indentiy create an Indentiy matrix

func New

func New(rows, cols int, values ...float64) *Matrix

New returns a new matrix provided given the order . Ie rows and cols. Values are the values of a martix as cols, If less values are provided than the order zeros are used to fill the matrix .

Example
package main

import (
	"fmt"

	"github.com/Duncodes/mathlib/matrix"
)

func main() {
	m := matrix.New(1, 2, 4, 3)

	fmt.Println(m)
}
Output:

4 3

func NewFromArray

func NewFromArray(data [][]float64) *Matrix

NewFromArray creates new Matrix given a 2d sclice

Example

This creates a new Matrix from [][]float64

package main

import (
	"fmt"

	"github.com/Duncodes/mathlib/matrix"
)

func main() {
	m := matrix.NewFromArray([][]float64{{1, 2}, {1, 2}})

	fmt.Println(m)

}
Output:

func Ones

func Ones(rows, cols int) *Matrix

Ones create a ones matrix

func Zero

func Zero(rows, cols int) *Matrix

Zero creates a zero matrix

Example
package main

import (
	"fmt"

	"github.com/Duncodes/mathlib/matrix"
)

func main() {
	m := matrix.Zero(1, 3)
	fmt.Println(m)

}
Output:

0 0 0

func (*Matrix) Array

func (m *Matrix) Array() [][]float64

Array returns a 2d slice from a matrix

func (*Matrix) Get

func (m *Matrix) Get(row, col int) float64

Get gets the data item in the row and col provided, Note this is zero besed indexed.Hence the first element of the matrix is accessed using Get(0,0)

func (*Matrix) Set

func (m *Matrix) Set(row, col int, value float64)

Set changes the data value at row , col provided. Note set has a zero base index ie the first element of the first col is accessed via Set(0,0) not Set(1,1)

func (*Matrix) Size

func (m *Matrix) Size() (rows, cols int)

Size returns the rows and cols of a matrix

func (*Matrix) String

func (m *Matrix) String() string

String for string matrix formating

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL