Go 自建庫的使用教程與測試

附加一個Go庫的實現,相較于Python,Go的實現更較為日常,不需要額外增加setup.py類的文件去額外定義,計算和并發的性能更加。

1. 創建 Go 模塊項目結構

首先創建完整的項目結構:

gomathlib/
├── go.mod
├── go.sum
├── core/
│   ├── arithmetic.go
│   └── calculator.go
├── advanced/
│   ├── functions.go
│   └── statistics.go
├── constants/
│   └── constants.go
├── examples/
│   ├── basic_usage.go
│   └── advanced_usage.go
├── tests/
│   ├── core_test.go
│   ├── advanced_test.go
│   └── constants_test.go
└── README.md

2. 初始化 Go 模塊

# 創建項目目錄
mkdir gomathlib
cd gomathlib# 初始化 Go 模塊
go mod init github.com/yourusername/gomathlib# 創建目錄結構
mkdir -p core advanced constants examples tests

3. 核心代碼實現

3.1 go.mod

module github.com/yourusername/gomathlibgo 1.21require (github.com/stretchr/testify v1.8.4
)

3.2 core/arithmetic.go

package coreimport ("errors""math"
)// Arithmetic 提供基礎算術運算
type Arithmetic struct {precision int
}// NewArithmetic 創建新的算術運算實例
func NewArithmetic(precision int) *Arithmetic {return &Arithmetic{precision: precision}
}// Add 加法運算,支持多個參數
func (a *Arithmetic) Add(numbers ...float64) float64 {var sum float64for _, num := range numbers {sum += num}return a.round(sum)
}// Subtract 減法運算
func (a *Arithmetic) Subtract(aVal, bVal float64) float64 {return a.round(aVal - bVal)
}// Multiply 乘法運算,支持多個參數
func (a *Arithmetic) Multiply(numbers ...float64) float64 {product := 1.0for _, num := range numbers {product *= num}return a.round(product)
}// Divide 除法運算
func (a *Arithmetic) Divide(dividend, divisor float64) (float64, error) {if divisor == 0 {return 0, errors.New("division by zero is not allowed")}return a.round(dividend / divisor), nil
}// Power 冪運算
func (a *Arithmetic) Power(base, exponent float64) float64 {return a.round(math.Pow(base, exponent))
}// Sqrt 平方根運算
func (a *Arithmetic) Sqrt(number float64) (float64, error) {if number < 0 {return 0, errors.New("cannot calculate square root of negative number")}return a.round(math.Sqrt(number)), nil
}// round 四舍五入到指定精度
func (a *Arithmetic) round(value float64) float64 {if a.precision < 0 {return value}shift := math.Pow(10, float64(a.precision))return math.Round(value*shift) / shift
}

3.3 core/calculator.go

package coreimport ("fmt""strings"
)// Calculator 提供鏈式計算功能
type Calculator struct {result   float64history  []stringprecision int
}// NewCalculator 創建新的計算器實例
func NewCalculator(initialValue float64, precision int) *Calculator {return &Calculator{result:   initialValue,history:  []string{fmt.Sprintf("Initial value: %.2f", initialValue)},precision: precision,}
}// Add 加法操作
func (c *Calculator) Add(value float64) *Calculator {c.result += valuec.history = append(c.history, fmt.Sprintf("+ %.2f", value))return c
}// Subtract 減法操作
func (c *Calculator) Subtract(value float64) *Calculator {c.result -= valuec.history = append(c.history, fmt.Sprintf("- %.2f", value))return c
}// Multiply 乘法操作
func (c *Calculator) Multiply(value float64) *Calculator {c.result *= valuec.history = append(c.history, fmt.Sprintf("* %.2f", value))return c
}// Divide 除法操作
func (c *Calculator) Divide(value float64) (*Calculator, error) {if value == 0 {return nil, fmt.Errorf("division by zero")}c.result /= valuec.history = append(c.history, fmt.Sprintf("/ %.2f", value))return c, nil
}// GetResult 獲取當前結果
func (c *Calculator) GetResult() float64 {// 使用內置的round方法shift := math.Pow(10, float64(c.precision))return math.Round(c.result*shift) / shift
}// Clear 清除計算歷史
func (c *Calculator) Clear() *Calculator {c.result = 0c.history = []string{"Cleared"}return c
}// GetHistory 獲取計算歷史
func (c *Calculator) GetHistory() []string {return c.history
}// String 返回計算歷史的字符串表示
func (c *Calculator) String() string {return strings.Join(c.history, " → ")
}

3.4 advanced/functions.go

package advancedimport ("errors""math"
)// MathFunctions 提供高級數學函數
type MathFunctions struct{}// NewMathFunctions 創建新的數學函數實例
func NewMathFunctions() *MathFunctions {return &MathFunctions{}
}// Factorial 計算階乘
func (mf *MathFunctions) Factorial(n int) (int, error) {if n < 0 {return 0, errors.New("factorial is not defined for negative numbers")}if n == 0 {return 1, nil}result := 1for i := 1; i <= n; i++ {result *= i}return result, nil
}// IsPrime 判斷是否為質數
func (mf *MathFunctions) IsPrime(n int) bool {if n <= 1 {return false}if n <= 3 {return true}if n%2 == 0 || n%3 == 0 {return false}for i := 5; i*i <= n; i += 6 {if n%i == 0 || n%(i+2) == 0 {return false}}return true
}// Fibonacci 生成斐波那契數列
func (mf *MathFunctions) Fibonacci(n int) ([]int, error) {if n < 0 {return nil, errors.New("n must be non-negative")}if n == 0 {return []int{}, nil}if n == 1 {return []int{0}, nil}if n == 2 {return []int{0, 1}, nil}fib := make([]int, n)fib[0] = 0fib[1] = 1for i := 2; i < n; i++ {fib[i] = fib[i-1] + fib[i-2]}return fib, nil
}// Log 計算對數
func (mf *MathFunctions) Log(number, base float64) (float64, error) {if number <= 0 || base <= 0 || base == 1 {return 0, errors.New("invalid arguments for logarithm")}return math.Log(number) / math.Log(base), nil
}// Sin 計算正弦值(弧度)
func (mf *MathFunctions) Sin(radians float64) float64 {return math.Sin(radians)
}// Cos 計算余弦值(弧度)
func (mf *MathFunctions) Cos(radians float64) float64 {return math.Cos(radians)
}

3.5 advanced/statistics.go

package advancedimport ("errors""math""sort"
)// Statistics 提供統計計算功能
type Statistics struct{}// NewStatistics 創建新的統計實例
func NewStatistics() *Statistics {return &Statistics{}
}// Mean 計算平均值
func (s *Statistics) Mean(numbers []float64) (float64, error) {if len(numbers) == 0 {return 0, errors.New("empty slice provided")}sum := 0.0for _, num := range numbers {sum += num}return sum / float64(len(numbers)), nil
}// Median 計算中位數
func (s *Statistics) Median(numbers []float64) (float64, error) {if len(numbers) == 0 {return 0, errors.New("empty slice provided")}sorted := make([]float64, len(numbers))copy(sorted, numbers)sort.Float64s(sorted)n := len(sorted)if n%2 == 0 {return (sorted[n/2-1] + sorted[n/2]) / 2, nil}return sorted[n/2], nil
}// Mode 計算眾數
func (s *Statistics) Mode(numbers []float64) ([]float64, error) {if len(numbers) == 0 {return nil, errors.New("empty slice provided")}frequency := make(map[float64]int)for _, num := range numbers {frequency[num]++}maxFreq := 0for _, freq := range frequency {if freq > maxFreq {maxFreq = freq}}var modes []float64for num, freq := range frequency {if freq == maxFreq {modes = append(modes, num)}}return modes, nil
}// StandardDeviation 計算標準差
func (s *Statistics) StandardDeviation(numbers []float64) (float64, error) {if len(numbers) < 2 {return 0, errors.New("at least two numbers required for standard deviation")}mean, err := s.Mean(numbers)if err != nil {return 0, err}sumSq := 0.0for _, num := range numbers {diff := num - meansumSq += diff * diff}variance := sumSq / float64(len(numbers)-1)return math.Sqrt(variance), nil
}// Variance 計算方差
func (s *Statistics) Variance(numbers []float64) (float64, error) {if len(numbers) < 2 {return 0, errors.New("at least two numbers required for variance")}mean, err := s.Mean(numbers)if err != nil {return 0, err}sumSq := 0.0for _, num := range numbers {diff := num - meansumSq += diff * diff}return sumSq / float64(len(numbers)-1), nil
}

3.6 constants/constants.go

package constants// MathConstants 包含常用數學常量
type MathConstants struct {PI             float64E              float64GoldenRatio    float64EulerMascheroni float64LightSpeed     float64
}// NewMathConstants 創建數學常量實例
func NewMathConstants() *MathConstants {return &MathConstants{PI:              3.14159265358979323846,E:               2.71828182845904523536,GoldenRatio:     1.61803398874989484820,EulerMascheroni: 0.57721566490153286060,LightSpeed:      299792458, // m/s}
}// 包級常量
var (PI          = 3.14159265358979323846E           = 2.71828182845904523536GoldenRatio = 1.61803398874989484820
)

4. 使用教程

4.1 安裝依賴

# 下載依賴
go mod tidy# 或者手動安裝測試框架
go get github.com/stretchr/testify

4.2 基本使用示例 examples/basic_usage.go

package mainimport ("fmt""log""github.com/yourusername/gomathlib/core""github.com/yourusername/gomathlib/advanced""github.com/yourusername/gomathlib/constants"
)func main() {fmt.Println("=== GoMathLib 基本使用示例 ===")// 基礎算術運算arithmetic := core.NewArithmetic(4)fmt.Println("\n1. 基礎運算:")fmt.Printf("加法: %.4f\n", arithmetic.Add(1.2345, 2.3456))fmt.Printf("乘法: %.4f\n", arithmetic.Multiply(3, 4, 5))result, err := arithmetic.Divide(22, 7)if err != nil {log.Fatal(err)}fmt.Printf("除法: %.4f\n", result)// 鏈式計算器fmt.Println("\n2. 鏈式計算器:")calc := core.NewCalculator(10, 2)calcResult, err := calc.Add(5).Multiply(3).Subtract(2).Divide(4)if err != nil {log.Fatal(err)}fmt.Printf("計算結果: %.2f\n", calcResult.GetResult())fmt.Printf("計算歷史: %s\n", calcResult.String())// 高級函數fmt.Println("\n3. 高級函數:")mathFuncs := advanced.NewMathFunctions()factorial, err := mathFuncs.Factorial(5)if err != nil {log.Fatal(err)}fmt.Printf("5的階乘: %d\n", factorial)fmt.Printf("17是質數: %t\n", mathFuncs.IsPrime(17))fib, err := mathFuncs.Fibonacci(10)if err != nil {log.Fatal(err)}fmt.Printf("斐波那契數列: %v\n", fib)// 數學常量fmt.Println("\n4. 數學常量:")mathConsts := constants.NewMathConstants()fmt.Printf("圓周率: %.10f\n", mathConsts.PI)fmt.Printf("自然常數e: %.10f\n", mathConsts.E)fmt.Printf("黃金比例: %.10f\n", mathConsts.GoldenRatio)fmt.Printf("光速: %.0f m/s\n", mathConsts.LightSpeed)
}

5. 測試用例

5.1 tests/core_test.go

package testsimport ("testing""github.com/yourusername/gomathlib/core""github.com/stretchr/testify/assert"
)func TestArithmetic(t *testing.T) {arithmetic := core.NewArithmetic(4)t.Run("Test Addition", func(t *testing.T) {result := arithmetic.Add(1, 2, 3, 4)assert.Equal(t, 10.0, result)})t.Run("Test Multiplication", func(t *testing.T) {result := arithmetic.Multiply(2, 3, 4)assert.Equal(t, 24.0, result)})t.Run("Test Division", func(t *testing.T) {result, err := arithmetic.Divide(10, 2)assert.NoError(t, err)assert.Equal(t, 5.0, result)})t.Run("Test Division By Zero", func(t *testing.T) {_, err := arithmetic.Divide(10, 0)assert.Error(t, err)})t.Run("Test Precision", func(t *testing.T) {result := arithmetic.Add(1.23456, 2.34567)assert.Equal(t, 3.5802, result) // Rounded to 4 decimal places})
}func TestCalculator(t *testing.T) {t.Run("Test Calculator Chain", func(t *testing.T) {calc := core.NewCalculator(10, 2)result, err := calc.Add(5).Multiply(3).Subtract(2).Divide(4)assert.NoError(t, err)assert.Equal(t, 9.75, result.GetResult())})t.Run("Test Calculator Division By Zero", func(t *testing.T) {calc := core.NewCalculator(10, 2)_, err := calc.Divide(0)assert.Error(t, err)})t.Run("Test Calculator History", func(t *testing.T) {calc := core.NewCalculator(0, 2)calc.Add(5).Multiply(2)history := calc.GetHistory()assert.Len(t, history, 3) // Initial + Add + Multiply})
}

5.2 tests/advanced_test.go

package testsimport ("testing""github.com/yourusername/gomathlib/advanced""github.com/stretchr/testify/assert"
)func TestMathFunctions(t *testing.T) {mathFuncs := advanced.NewMathFunctions()t.Run("Test Factorial", func(t *testing.T) {result, err := mathFuncs.Factorial(5)assert.NoError(t, err)assert.Equal(t, 120, result)})t.Run("Test Factorial Negative", func(t *testing.T) {_, err := mathFuncs.Factorial(-1)assert.Error(t, err)})t.Run("Test IsPrime", func(t *testing.T) {assert.True(t, mathFuncs.IsPrime(2))assert.True(t, mathFuncs.IsPrime(17))assert.False(t, mathFuncs.IsPrime(1))assert.False(t, mathFuncs.IsPrime(15))})t.Run("Test Fibonacci", func(t *testing.T) {result, err := mathFuncs.Fibonacci(10)assert.NoError(t, err)expected := []int{0, 1, 1, 2, 3, 5, 8, 13, 21, 34}assert.Equal(t, expected, result)})
}func TestStatistics(t *testing.T) {stats := advanced.NewStatistics()numbers := []float64{1, 2, 3, 4, 5, 5, 6}t.Run("Test Mean", func(t *testing.T) {result, err := stats.Mean(numbers)assert.NoError(t, err)assert.Equal(t, 3.7142857142857144, result)})t.Run("Test Median", func(t *testing.T) {result, err := stats.Median(numbers)assert.NoError(t, err)assert.Equal(t, 4.0, result)})t.Run("Test Mode", func(t *testing.T) {result, err := stats.Mode(numbers)assert.NoError(t, err)assert.Equal(t, []float64{5}, result)})t.Run("Test Empty Slice", func(t *testing.T) {_, err := stats.Mean([]float64{})assert.Error(t, err)})
}

5.3 tests/constants_test.go

package testsimport ("testing""github.com/yourusername/gomathlib/constants""github.com/stretchr/testify/assert"
)func TestConstants(t *testing.T) {mathConsts := constants.NewMathConstants()t.Run("Test PI", func(t *testing.T) {assert.Equal(t, 3.14159265358979323846, mathConsts.PI)assert.Equal(t, mathConsts.PI, constants.PI)})t.Run("Test E", func(t *testing.T) {assert.Equal(t, 2.71828182845904523536, mathConsts.E)assert.Equal(t, mathConsts.E, constants.E)})t.Run("Test GoldenRatio", func(t *testing.T) {assert.Equal(t, 1.61803398874989484820, mathConsts.GoldenRatio)assert.Equal(t, mathConsts.GoldenRatio, constants.GoldenRatio)})
}

6. 運行測試和示例

6.1 運行測試

# 運行所有測試
go test ./tests/ -v# 運行特定測試
go test ./tests/ -run TestArithmetic -v# 運行帶覆蓋率的測試
go test ./tests/ -cover -v# 生成HTML覆蓋率報告
go test ./tests/ -coverprofile=coverage.out
go tool cover -html=coverage.out

6.2 運行示例

# 運行基本使用示例
go run examples/basic_usage.go# 構建示例
go build -o examples/basic_usage examples/basic_usage.go
./examples/basic_usage

7. 發布和使用

7.1 在其他項目中使用

package mainimport ("fmt""github.com/yourusername/gomathlib/core""github.com/yourusername/gomathlib/advanced"
)func main() {// 使用算術運算math := core.NewArithmetic(2)fmt.Printf("Result: %.2f\n", math.Add(1.23, 4.56))// 使用高級函數adv := advanced.NewMathFunctions()isPrime := adv.IsPrime(29)fmt.Printf("Is 29 prime? %t\n", isPrime)
}

7.2 在其他項目中引用

# 在其他Go項目中引用
go mod init myapp
go mod edit -require github.com/yourusername/gomathlib@v0.1.0
go mod edit -replace github.com/yourusername/gomathlib=../gomathlib
go mod tidy

8. 創建文檔

8.1 生成Godoc

# 啟動本地Godoc服務器
godoc -http=:6060# 然后在瀏覽器訪問: http://localhost:6060/pkg/github.com/yourusername/gomathlib/

8.2 README.md

# GoMathLib一個功能強大的Go數學運算庫,提供基礎運算、高級函數和統計計算。## 安裝```bash
go get github.com/yourusername/gomathlib

快速開始

package mainimport ("fmt""github.com/yourusername/gomathlib/core"
)func main() {math := core.NewArithmetic(2)result := math.Add(1.23, 4.56)fmt.Printf("Result: %.2f\n", result)
}

功能特性

  • 基礎四則運算
  • 鏈式計算器
  • 高級數學函數(階乘、質數判斷、斐波那契數列)
  • 統計計算(平均值、中位數、眾數、標準差)
  • 數學常量

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/97942.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/97942.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/97942.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

What is a prototype network in few-shot learning?

A prototype network is a method used in few-shot learning to classify new data points when only a small number of labeled examples (the “shots”) are available per class. It works by creating a representative “prototype” for each class, which is typical…

Linux中用于線程/進程同步的核心函數——`sem_wait`函數

<摘要> sem_wait 是 POSIX 信號量操作函數&#xff0c;用于對信號量執行 P 操作&#xff08;等待、獲取&#xff09;。它的核心功能是原子地將信號量的值減 1。如果信號量的值大于 0&#xff0c;則減 1 并立即返回&#xff1b;如果信號量的值為 0&#xff0c;則調用線程&…

25高教社杯數模國賽【B題超高質量思路+問題分析】

注&#xff1a;本內容由”數模加油站“ 原創出品&#xff0c;雖無償分享&#xff0c;但創作不易。 歡迎參考teach&#xff0c;但請勿抄襲、盜賣或商用。 B 題 碳化硅外延層厚度的確定碳化硅作為一種新興的第三代半導體材料&#xff0c;以其優越的綜合性能表現正在受到越來越多…

【Linux篇章】再續傳輸層協議UDP :從低可靠到極速傳輸的協議重生之路,揭秘無連接通信的二次進化密碼!

&#x1f4cc;本篇摘要&#xff1a; 本篇將承接上次的UDP系列網絡編程&#xff0c;來深入認識下UDP協議的結構&#xff0c;特性&#xff0c;底層原理&#xff0c;注意事項及應用場景&#xff01; &#x1f3e0;歡迎拜訪&#x1f3e0;&#xff1a;點擊進入博主主頁 &#x1f4c…

《A Study of Probabilistic Password Models》(IEEE SP 2014)——論文閱讀

提出更高效的密碼評估工具&#xff0c;將統計語言建模技術引入密碼建模&#xff0c;系統評估各類概率密碼模型性能&#xff0c;打破PCFGw的 “最優模型” 認知。一、研究背景當前研究存在兩大關鍵問題&#xff1a;一是主流的 “猜測數圖” 計算成本極高&#xff0c;且難以覆蓋強…

校園外賣點餐系統(代碼+數據庫+LW)

摘要 隨著校園生活節奏的加快&#xff0c;學生對外賣的需求日益增長。然而&#xff0c;傳統的外賣服務存在諸多不便&#xff0c;如配送時間長、菜品選擇有限、信息更新不及時等。為解決這些問題&#xff0c;本研究開發了一款校園外賣點餐系統&#xff0c;采用前端 Vue、后端 S…

友思特案例 | 食品行業視覺檢測案例集錦(三)

食品制造質量檢測對保障消費者安全和產品質量穩定至關重要&#xff0c;覆蓋原材料至成品全階段&#xff0c;含過程中檢測與成品包裝檢測。近年人工智能深度學習及自動化系統正日益融入食品生產。本篇文章將介紹案例三&#xff1a;友思特Neuro-T深度學習平臺進行面餅質量檢測。在…

SQLynx 3.7 發布:數據庫管理工具的性能與交互雙重進化

目錄 &#x1f511; 核心功能更新 1. 單頁百萬級數據展示 2. 更安全的數據更新與刪除機制 3. 更智能的 SQL 代碼提示 4. 新增物化視圖與外表支持 5. 數據庫搜索與過濾功能重構 ? 總結與思考 在大數據與云原生應用快速發展的今天&#xff0c;數據庫管理工具不僅要“能用…

10G網速不是夢!5G-A如何“榨干”毫米波,跑出比5G快10倍的速度?

5G-A&#xff08;5G-Advanced&#xff09;網絡技術已經在中國福建省廈門市軟件園成功實現萬兆&#xff08;10Gbps&#xff09;速率驗證&#xff0c;標志著我國正式進入5G增強版商用階段。這一突破性成果不僅驗證了5G-A技術的可行性&#xff0c;也為6G網絡的發展奠定了堅實基礎。…

Linux筆記---UDP套接字實戰:簡易聊天室

1. 項目需求分析 我們要設計的是一個簡單的匿名聊天室&#xff0c;用戶的客戶端要求用戶輸入自己的昵稱之后即可在一個公共的群聊當中聊天。 為了簡單起見&#xff0c;我們設計用戶在終端當中與客戶端交互&#xff0c;而在一個文件當中顯式群聊信息&#xff1a; 當用戶輸入的…

RTP打包與解包全解析:從RFC規范到跨平臺輕量級RTSP服務和低延遲RTSP播放器實現

引言 在實時音視頻系統中&#xff0c;RTSP&#xff08;Real-Time Streaming Protocol&#xff09;負責會話與控制&#xff0c;而 RTP&#xff08;Real-time Transport Protocol&#xff09;負責媒體數據承載。開發者在實現跨平臺、低延遲的 RTSP 播放器或輕量級 RTSP 服務時&a…

Ubuntu 用戶和用戶組

一、 Linux 用戶linux 是一個多用戶操作系統&#xff0c;不同的用戶擁有不同的權限&#xff0c;可以查看和操作不同的文件。 Ubuntu 有三種用戶1、初次創建的用戶2、root 用戶---上帝3、普通用戶初次創建的用戶權限比普通用戶要多&#xff0c;但是沒有 root 用戶多。Linux 用戶…

FastGPT社區版大語言模型知識庫、Agent開源項目推薦

? FastGPT 項目說明 項目概述 FastGPT 是一個基于大語言模型&#xff08;LLM&#xff09;的知識庫問答系統&#xff0c;提供開箱即用的數據處理和模型調用能力&#xff0c;支持通過可視化工作流編排實現復雜問答場景。 技術架構 前端: Next.js TypeScript Chakra UI 后…

jsencrypt公鑰分段加密,支持后端解密

前端使用jsencryp實現分段加密。 解決長文本RSA加密報錯問題。 支持文本包含中文。 支持后端解密。前端加密代碼&#xff1a; // import { JSEncrypt } from jsencrypt const JSEncrypt require(jsencrypt) /*** 使用 JSEncrypt 實現分段 RSA 加密&#xff08;正確處理中文字符…

生成一份關于電腦電池使用情況、健康狀況和壽命估算的詳細 HTML 報告

核心作用 powercfg /batteryreport 是一個在 Windows 命令提示符或 PowerShell 中運行的命令。它的核心作用是&#xff1a;生成一份關于電腦電池使用情況、健康狀況和壽命估算的詳細 HTML 報告。 這份報告非常有用&#xff0c;特別是對于筆記本電腦用戶&#xff0c;它可以幫你&…

從 0 到 1 實現 PyTorch 食物圖像分類:核心知識點與完整實

食物圖像分類是計算機視覺的經典任務之一&#xff0c;其核心是讓機器 “看懂” 圖像中的食物類別。隨著深度學習的發展&#xff0c;卷積神經網絡&#xff08;CNN&#xff09;憑借強大的特征提取能力&#xff0c;成為圖像分類的主流方案。本文將基于 PyTorch 框架&#xff0c;從…

Python 值傳遞 (Pass by Value) 和引用傳遞 (Pass by Reference)

Python 值傳遞 {Pass by Value} 和引用傳遞 {Pass by Reference}1. Mutable Objects and Immutable Objects in Python (Python 可變對象和不可變對象)2. Pass by Value and Pass by Reference2.1. What is Pass by Value in Python?2.2. What is Pass by Reference in Python…

aippt自動生成工具有哪些?一文看懂,總有一款適合你!

在當今快節奏的工作與學習環境中&#xff0c;傳統耗時的PPT制作方式已難以滿足高效表達的需求。隨著人工智能技術的發展&#xff0c;AI自動生成PPT工具應運而生&#xff0c;成為提升演示文稿制作效率的利器。這類工具通過自然語言處理和深度學習技術&#xff0c;能夠根據用戶輸…

Langflow 框架中 Prompt 技術底層實現分析

Langflow 框架中 Prompt 技術底層實現分析 1. Prompt 技術概述 Langflow 是一個基于 LangChain 的可視化 AI 工作流構建框架&#xff0c;其 Prompt 技術是整個系統的核心組件之一。Prompt 技術主要負責&#xff1a; 模板化處理&#xff1a;支持動態變量替換的提示詞模板變量驗證…

前端、node跨域問題

前端頁面訪問node后端接口跨域報錯 Access to XMLHttpRequest at http://192.18.31.75/api/get?namess&age19 from origin http://127.0.0.1:5500 has been blocked by CORS policy: No Access-Control-Allow-Origin header is present on the requested resource. 這個報…