mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-26 13:49:14 +08:00
Add docs to StringFrame.
This commit is contained in:
parent
cbc7ab2c3d
commit
317be550f2
@ -1,21 +1,26 @@
|
|||||||
package data
|
package data
|
||||||
|
|
||||||
|
// Used for storing matrix-like strings. For example, if you have multiple labels associated with each instance, then you probably need a matrix-like struct to store whole your labels.
|
||||||
type StringFrame struct {
|
type StringFrame struct {
|
||||||
labels [][]string
|
labels [][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a row of string to StringFrame
|
||||||
func (self *StringFrame) Add(row []string) {
|
func (self *StringFrame) Add(row []string) {
|
||||||
self.labels = append(self.labels, row)
|
self.labels = append(self.labels, row)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the string at (i, j)
|
||||||
func (self *StringFrame) At(i, j int) string {
|
func (self *StringFrame) At(i, j int) string {
|
||||||
return self.labels[i][j]
|
return self.labels[i][j]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the i-th row of string
|
||||||
func (self *StringFrame) Row(i int) []string {
|
func (self *StringFrame) Row(i int) []string {
|
||||||
return self.labels[i]
|
return self.labels[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the j-th column of string
|
||||||
func (self *StringFrame) Col(j int) []string {
|
func (self *StringFrame) Col(j int) []string {
|
||||||
col := make([]string, 0)
|
col := make([]string, 0)
|
||||||
for i := 0; i < self.NRow(); i++ {
|
for i := 0; i < self.NRow(); i++ {
|
||||||
@ -25,10 +30,12 @@ func (self *StringFrame) Col(j int) []string {
|
|||||||
return col
|
return col
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Number of rows
|
||||||
func (self *StringFrame) NRow() int {
|
func (self *StringFrame) NRow() int {
|
||||||
return len(self.labels)
|
return len(self.labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Number of columns
|
||||||
func (self *StringFrame) NCol() int {
|
func (self *StringFrame) NCol() int {
|
||||||
return len(self.labels[0])
|
return len(self.labels[0])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user