Rust vs Go:常用语法对比(八)

alt

题目来自 Golang vs. Rust: Which Programming Language To Choose in 2023?[1]


141. Iterate in sequence over two lists

Iterate in sequence over the elements of the list items1 then items2. For each iteration print the element.

依次迭代两个列表 依次迭代列表项1和项2的元素。每次迭代打印元素。

package main

import (
 "fmt"
)

func main() {
 items1 := []string{"a""b""c"}
 items2 := []string{"A""B""C"}

 for _, v := range items1 {
  fmt.Println(v)
 }
 for _, v := range items2 {
  fmt.Println(v)
 }
}

a
b
c
A
B
C

fn main() {
    let item1 = vec!["1""2""3"];
    let item2 = vec!["a""b""c"];
    for i in item1.iter().chain(item2.iter()) {
        print!("{} ", i);
    }
}

1 2 3 a b c


142. Hexadecimal digits of an integer

Assign to string s the hexadecimal representation (base 16) of integer x.
E.g. 999 -> "3e7"

将整数x的十六进制表示(16进制)赋给字符串s。

package main

import "fmt"
import "strconv"

func main() {
 x := int64(999)
 s := strconv.FormatInt(x, 16)

 fmt.Println(s)
}

3e7

or

package main

import (
 "fmt"
 "math/big"
)

func main() {
 x := big.NewInt(999)
 s := fmt.Sprintf("%x", x)

 fmt.Println(s)
}

3e7


fn main() {
    let x = 999;

    let s = format!("{:X}", x);
    println!("{}", s);

    let s = format!("{:x}", x);
    println!("{}", s);
}

{:X} produces uppercase hex. {:x} produces lowercase hex.

3E7
3e7

143. Iterate alternatively over two lists

Iterate alternatively over the elements of the list items1 and items2. For each iteration, print the element.
Explain what happens if items1 and items2 have different size.

交替迭代两个列表

package main

import (
 "fmt"
)

func main() {
 items1 := []string{"a""b"}
 items2 := []string{"A""B""C"}

 for i := 0; i < len(items1) || i < len(items2); i++ {
  if i < len(items1) {
   fmt.Println(items1[i])
  }
  if i < len(items2) {
   fmt.Println(items2[i])
  }
 }
}

a
A
b
B
C

extern crate itertools;
use itertools::izip;

fn main() {
    let items1 = [51525];
    let items2 = [102030];

    for pair in izip!(&items1, &items2) {
        println!("{}", pair.0);
        println!("{}", pair.1);
    }
}

5
10
15
20
25
30

144. Check if file exists

Set boolean b to true if file at path fp exists on filesystem; false otherwise.
Beware that you should never do this and then in the next instruction assume the result is still valid, this is a race condition on any multitasking OS.

检查文件是否存在

package main

import (
 "fmt"
 "io/ioutil"
 "os"
)

func main() {
 fp := "foo.txt"
 _, err := os.Stat(fp)
 b := !os.IsNotExist(err)
 fmt.Println(fp, "exists:", b)

 fp = "bar.txt"
 _, err = os.Stat(fp)
 b = !os.IsNotExist(err)
 fmt.Println(fp, "exists:", b)
}

func init() {
 ioutil.WriteFile("foo.txt", []byte(`abc`), 0644)
}

There's no specific existence check func in standard library, so we have to inspect an error return value.

foo.txt exists: true
bar.txt exists: false

fn main() {
    let fp = "/etc/hosts";
    let b = std::path::Path::new(fp).exists();
    println!("{}: {}", fp, b);

    let fp = "/etc/kittens";
    let b = std::path::Path::new(fp).exists();
    println!("{}: {}", fp, b);
}

/etc/hosts: true
/etc/kittens: false

145. Print log line with datetime

Print message msg, prepended by current date and time.
Explain what behavior is idiomatic: to stdout or stderr, and what the date format is.

打印带时间的日志

package main

import "log"

func main() {
 msg := "Hello, playground"
 log.Println(msg)

 // The date is fixed in the past in the Playground, never mind.
}

// See http://www.programming-idioms.org/idiom/145/print-log-line-with-date/1815/go

2009/11/10 23:00:00 Hello, playground


fn main() {
    let msg = "Hello";
    eprintln!("[{}] {}", humantime::format_rfc3339_seconds(std::time::SystemTime::now()), msg);
}

[2021-07-17T07:14:03Z] Hello


146. Convert string to floating point number

Extract floating point value f from its string representation s

字符串转换为浮点型

package main

import (
 "fmt"
 "strconv"
)

func main() {
 s := "3.1415926535"

 f, err := strconv.ParseFloat(s, 64)
 fmt.Printf("%T, %v, err=%v\n", f, f, err)
}

//
// http://www.programming-idioms.org/idiom/146/convert-string-to-floating-point-number/1819/go
//

float64, 3.1415926535, err=<nil>


fn main() {
    let s = "3.14159265359";
    let f = s.parse::<f32>().unwrap();
    
    println!("{}² = {}" , f, f * f);
}

3.1415927² = 9.869605

or

fn main() {
    let s = "3.14159265359";
    let f: f32 = s.parse().unwrap();

    println!("{}² = {}", f, f * f);
}

3.1415927² = 9.869605


147. Remove all non-ASCII characters

Create string t from string s, keeping only ASCII characters

移除所有的非ASCII字符

package main

import (
 "fmt"
 "regexp"
)

func main() {
 s := "dæmi : пример : příklad : thí dụ"

 re := regexp.MustCompile("[[:^ascii:]]")
 t := re.ReplaceAllLiteralString(s, "")

 fmt.Println(t)
}

dmi : : pklad : th d

or

package main

import (
 "fmt"
 "strings"
 "unicode"
)

func main() {
 s := "5#∑∂ƒ∞645eyfu"
 t := strings.Map(func(r rune) rune {
  if r > unicode.MaxASCII {
   return -1
  }
  return r
 }, s)
 fmt.Println(t)
}

5#645eyfu


fn main() {
    println!("{}""do👍ot".replace(|c: char| !c.is_ascii(), ""))
}

doot

or

fn main() {
    println!("{}""do👍ot".replace(|c: char| !c.is_ascii(), ""))
}

doot


148. Read list of integers from stdin

Read a list of integer numbers from the standard input, until EOF.

从stdin(标准输入)中读取整数列表

package main

import (
 "bufio"
 "fmt"
 "log"
 "strconv"
 "strings"
)

func main() {
 var ints []int
 s := bufio.NewScanner(osStdin)
 s.Split(bufio.ScanWords)
 for s.Scan() {
  i, err := strconv.Atoi(s.Text())
  if err == nil {
   ints = append(ints, i)
  }
 }
 if err := s.Err(); err != nil {
  log.Fatal(err)
 }
 fmt.Println(ints)
}

// osStdin simulates os.Stdin
var osStdin = strings.NewReader(`
11
22
33  `
)

[11 22 33]


use std::{
    io::{self, Read},
    str::FromStr,
};

// dummy io::stdin
fn io_stdin() -> impl Read {
    "123
456
789"

    .as_bytes()
}

fn main() -> io::Result<()> {
    let mut string = String::new();
    io_stdin().read_to_string(&mut string)?;
    let result = string
        .lines()
        .map(i32::from_str)
        .collect::<Result<Vec<_>, _>>();
    println!("{:#?}", result);
    Ok(())
}
Ok(
    [
        123,
        456,
        789,
    ],
)

150. Remove trailing slash

Remove last character from string p, if this character is a slash /.

去除末尾的 /

package main

import (
 "fmt"
 "strings"
)

func main() {
 p := "/usr/bin/"

 p = strings.TrimSuffix(p, "/")

 fmt.Println(p)
}

/usr/bin


fn main() {
    let mut p = String::from("Dddd/");
    if p.ends_with('/') {
        p.pop();
    }
    println!("{}", p);
}

Dddd


151. Remove string trailing path separator

Remove last character from string p, if this character is the file path separator of current platform.
Note that this also transforms unix root path "/" into the empty string!

删除字符串尾部路径分隔符

package main

import (
 "fmt"
 "io/ioutil"
 "os"
 "strings"
)

func main() {
 p := somePath()
 fmt.Println(p)

 sep := fmt.Sprintf("%c", os.PathSeparator)
 p = strings.TrimSuffix(p, sep)

 fmt.Println(p)
}

func somePath() string {
 dir, err := ioutil.TempDir("""")
 if err != nil {
  panic(err)
 }
 p := fmt.Sprintf("%s%c%s%c", dir, os.PathSeparator, "foobar", os.PathSeparator)
 return p
}

/tmp/067319278/foobar/
/tmp/067319278/foobar

or

package main

import (
 "fmt"
 "io/ioutil"
 "os"
 "path/filepath"
 "strings"
)

func main() {
 p := somePath()
 fmt.Println(p)

 sep := fmt.Sprintf("%c", filepath.Separator)
 p = strings.TrimSuffix(p, sep)

 fmt.Println(p)
}

func somePath() string {
 dir, err := ioutil.TempDir("""")
 if err != nil {
  panic(err)
 }
 p := fmt.Sprintf("%s%c%s%c", dir, os.PathSeparator, "foobar", os.PathSeparator)
 return p
}
/tmp/065654753/foobar/
/tmp/065654753/foobar

fn main() {
    {
        let p = "/tmp/";

        let p = if ::std::path::is_separator(p.chars().last().unwrap()) {
            &p[0..p.len() - 1]
        } else {
            p
        };

        println!("{}", p);
    }
    
    {
        let p = "/tmp";

        let p = if ::std::path::is_separator(p.chars().last().unwrap()) {
            &p[0..p.len() - 1]
        } else {
            p
        };

        println!("{}", p);
    }
}
/tmp
/tmp

or

fn main() {
    {
        let mut p = "/tmp/";

        p = p.strip_suffix(std::path::is_separator).unwrap_or(p);

        println!("{}", p);
    }
    
    {
        let mut p = "/tmp";

        p = p.strip_suffix(std::path::is_separator).unwrap_or(p);

        println!("{}", p);
    }
}
/tmp
/tmp

152. Turn a character into a string

Create string s containing only the character c.

将字符转换成字符串

package main

import (
 "fmt"
 "os"
)

func main() {
 var c rune = os.PathSeparator
 fmt.Printf("%c \n", c)

 s := fmt.Sprintf("%c", c)
 fmt.Printf("%#v \n", s)
}


"/" 

fn main() {
    let c = 'a';
    
    let s = c.to_string();
    
    println!("{}", s);
}

a


153. Concatenate string with integer

Create string t as the concatenation of string s and integer i.

连接字符串和整数

package main

import (
 "fmt"
)

func main() {
 s := "Hello"
 i := 123

 t := fmt.Sprintf("%s%d", s, i)

 fmt.Println(t)
}

Hello123


fn main() {
    let s = "Foo";
    let i = 1;
    let t = format!("{}{}", s, i);
    
    println!("{}" , t);
}

Foo1


154. Halfway between two hex color codes

Find color c, the average between colors c1, c2.
c, c1, c2 are strings of hex color codes: 7 chars, beginning with a number sign # . Assume linear computations, ignore gamma corrections.

求两个十六进制颜色代码的中间值

package main

import (
 "fmt"
 "strconv"
 "strings"
)

// For concision, halfway assume valid inputs.
// Caller must have explicitly checked that c1, c2 are well-formed color codes.
func halfway(c1, c2 string) string {
 r1, _ := strconv.ParseInt(c1[1:3], 160)
 r2, _ := strconv.ParseInt(c2[1:3], 160)
 r := (r1 + r2) / 2

 g1, _ := strconv.ParseInt(c1[3:5], 160)
 g2, _ := strconv.ParseInt(c2[3:5], 160)
 g := (g1 + g2) / 2

 b1, _ := strconv.ParseInt(c1[5:7], 160)
 b2, _ := strconv.ParseInt(c2[5:7], 160)
 b := (b1 + b2) / 2

 c := fmt.Sprintf("#%02X%02X%02X", r, g, b)
 return c
}

func main() {
 c1 := "#15293E"
 c2 := "#012549"

 if err := checkFormat(c1); err != nil {
  panic(fmt.Errorf("Wrong input %q: %v", c1, err))
 }
 if err := checkFormat(c2); err != nil {
  panic(fmt.Errorf("Wrong input %q: %v", c2, err))
 }

 c := halfway(c1, c2)
 fmt.Println("The average of", c1, "and", c2, "is", c)
}

func checkFormat(color string) error {
 if len(color) != 7 {
  return fmt.Errorf("Hex colors have exactly 7 chars")
 }
 if color[0] != '#' {
  return fmt.Errorf("Hex colors start with #")
 }
 isNotDigit := func(c rune) bool { return (c < '0' || c > '9') && (c < 'a' || c > 'f') }
 if strings.IndexFunc(strings.ToLower(color[1:]), isNotDigit) != -1 {
  return fmt.Errorf("Forbidden char")
 }
 return nil
}

The average of #15293E and #012549 is #0B2743

package main

import (
 "fmt"
 "strconv"
 "strings"
)

// For concision, halfway assume valid inputs.
// Caller must have explicitly checked that c1, c2 are well-formed color codes.
func halfway(c1, c2 string) string {
 var buf [7]byte
 buf[0] = '#'
 for i := 0; i < 3; i++ {
  sub1 := c1[1+2*i : 3+2*i]
  sub2 := c2[1+2*i : 3+2*i]
  v1, _ := strconv.ParseInt(sub1, 160)
  v2, _ := strconv.ParseInt(sub2, 160)
  v := (v1 + v2) / 2
  sub := fmt.Sprintf("%02X", v)
  copy(buf[1+2*i:3+2*i], sub)
 }
 c := string(buf[:])

 return c
}

func main() {
 c1 := "#15293E"
 c2 := "#012549"

 if err := checkFormat(c1); err != nil {
  panic(fmt.Errorf("Wrong input %q: %v", c1, err))
 }
 if err := checkFormat(c2); err != nil {
  panic(fmt.Errorf("Wrong input %q: %v", c2, err))
 }

 c := halfway(c1, c2)
 fmt.Println("The average of", c1, "and", c2, "is", c)
}

func checkFormat(color string) error {
 if len(color) != 7 {
  return fmt.Errorf("Hex colors have exactly 7 chars")
 }
 if color[0] != '#' {
  return fmt.Errorf("Hex colors start with #")
 }
 isNotDigit := func(c rune) bool { return (c < '0' || c > '9') && (c < 'a' || c > 'f') }
 if strings.IndexFunc(strings.ToLower(color[1:]), isNotDigit) != -1 {
  return fmt.Errorf("Forbidden char")
 }
 return nil
}

The average of #15293E and #012549 is #0B2743


use std::str::FromStr;
use std::fmt;

#[derive(Debug)]
struct Colour {
    r: u8,
    g: u8,
    b: u8
}

#[derive(Debug)]
enum ColourError {
    MissingHash,
    InvalidRed,
    InvalidGreen,
    InvalidBlue
}

impl fmt::Display for Colour {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "#{:02x}{:02x}{:02x}"self.r, self.g, self.b)
    }
}

impl FromStr for Colour {
    type Err = ColourError;
    
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if !s.starts_with('#') {
            Err(ColourError::MissingHash)
        } else {
            Ok(Colour {
                r: u8::from_str_radix(&s[1..3], 16).map_err(|_| ColourError::InvalidRed)?,
                g: u8::from_str_radix(&s[3..5], 16).map_err(|_| ColourError::InvalidGreen)?,
                b: u8::from_str_radix(&s[5..7], 16).map_err(|_| ColourError::InvalidBlue)?
            })
        }
    }
}

fn mid_colour(c1: &str, c2: &str) -> Result<String, ColourError> {
    let c1 = c1.parse::<Colour>()?;
    let c2 = c2.parse::<Colour>()?;
    let c = Colour {
        r: (((c1.r as u16) + (c2.r as u16))/2as u8,
        g: (((c1.g as u16) + (c2.g as u16))/2as u8,
        b: (((c1.b as u16) + (c2.b as u16))/2as u8
    };
    Ok(format!("{}", c))
}

fn main() {
    println!("{}", mid_colour("#15293E""#012549").unwrap())
}

#0b2743


155. Delete file

Delete from filesystem the file having path filepath.

删除文件

package main

import (
 "fmt"
 "io/ioutil"
 "os"
)

func main() {
 for _, filepath := range []string{
  "/tmp/foo.txt",
  "/tmp/bar.txt",
  "/tmp/foo.txt",
 } {
  err := os.Remove(filepath)
  if err == nil {
   fmt.Println("Removed", filepath)
  } else {
   fmt.Fprintln(os.Stderr, err)
  }
 }
}

func init() {
 err := ioutil.WriteFile("/tmp/foo.txt", []byte(`abc`), 0644)
 if err != nil {
  panic(err)
 }
}
Removed /tmp/foo.txt
remove /tmp/bar.txt: no such file or directory
remove /tmp/foo.txt: no such file or directory

use std::fs;

fn main() {
    let filepath = "/tmp/abc";

    println!("Creating {}", filepath);
    let _file = fs::File::create(filepath);

    let b = std::path::Path::new(filepath).exists();
    println!("{} exists: {}", filepath, b);

    println!("Deleting {}", filepath);
    let r = fs::remove_file(filepath);
    println!("{:?}", r);

    let b = std::path::Path::new(filepath).exists();
    println!("{} exists: {}", filepath, b);
}
Creating /tmp/abc
/tmp/abc exists: true
Deleting /tmp/abc
Ok(())
/tmp/abc exists: false

156. Format integer with zero-padding

Assign to string s the value of integer i in 3 decimal digits. Pad with zeros if i < 100. Keep all digits if i ≥ 1000.

用零填充格式化整数

package main

import (
 "fmt"
)

func main() {
 for _, i := range []int{
  0,
  8,
  64,
  256,
  2048,
 } {
  s := fmt.Sprintf("%03d", i)
  fmt.Println(s)
 }
}

000
008
064
256
2048

fn main() {
    let i = 1;
    let s = format!("{:03}", i);
    
    println!("{}", s);
    
    
    let i = 1000;
    let s = format!("{:03}", i);
    
    println!("{}", s);
}
001
1000

157. Declare constant string

Initialize a constant planet with string value "Earth".

声明常量字符串

package main

import (
 "fmt"
)

const planet = "Earth"

func main() {
 fmt.Println("We live on planet", planet)
}

We live on planet Earth


fn main() {
    const PLANET: &str = "Earth";
    
    println!("{}", PLANET);
}

Earth


158. Random sublist

Create a new list y from randomly picking exactly k elements from list x.

It is assumed that x has at least k elements. Each element must have same probability to be picked. Each element from x must be picked at most once. Explain if the original ordering is preserved or not.

随机子列表

package main

import (
 "fmt"
 "math/rand"
)

func main() {
 type T string

 x := []T{"Alice""Bob""Carol""Dan""Eve""Frank""Grace""Heidi"}
 k := 4

 y := make([]T, k)
 perm := rand.Perm(len(x))
 for i, v := range perm[:k] {
  y[i] = x[v]
 }

 fmt.Printf("%q", y)
}

["Frank" "Eve" "Carol" "Grace"]


use rand::prelude::*;
let mut rng = &mut rand::thread_rng();
let y = x.choose_multiple(&mut rng, k).cloned().collect::<Vec<_>>();

159. Trie

Define a Trie data structure, where entries have an associated value. (Not all nodes are entries)

前缀树/字典树

package main

import (
 "fmt"
 "unicode/utf8"
)

type Trie struct {
 c        rune
 children map[rune]*Trie
 isLeaf   bool
 value    V
}

type V int

func main() {
 t := NewTrie(0)
 for s, v := range map[string]V{
  "to":  7,
  "tea"3,
  "ted"4,
  "ten"12,
  "A":   15,
  "i":   11,
  "in":  5,
  "inn"9,
 } {
  t.insert(s, v)
 }
 fmt.Println(t.startsWith("te"""))
}

func NewTrie(c rune) *Trie {
 t := new(Trie)
 t.c = c
 t.children = map[rune]*Trie{}
 return t
}

func (t *Trie) insert(s string, value V) {
 if s == "" {
  t.isLeaf = true
  t.value = value
  return
 }
 c, tail := cut(s)
 child, exists := t.children[c]
 if !exists {
  child = NewTrie(c)
  t.children[c] = child
 }
 child.insert(tail, value)
}

func (t *Trie) startsWith(p string, accu string) []string {
 if t == nil {
  return nil
 }
 if p == "" {
  var result []string
  if t.isLeaf {
   result = append(result, accu)
  }
  for c, child := range t.children {
   rec := child.startsWith("", accu+string(c))
   result = append(result, rec...)
  }
  return result
 }
 c, tail := cut(p)
 return t.children[c].startsWith(tail, accu+string(c))
}

func cut(s string) (head rune, tail string) {
 r, size := utf8.DecodeRuneInString(s)
 return r, s[size:]
}

[ten tea ted]


struct Trie {
    val: String,
    nodes: Vec<Trie>
}

160. Detect if 32-bit or 64-bit architecture

Execute f32() if platform is 32-bit, or f64() if platform is 64-bit.
This can be either a compile-time condition (depending on target) or a runtime detection.

检测是32位还是64位架构

package main

import (
 "fmt"
 "strconv"
)

func main() {
 if strconv.IntSize == 32 {
  f32()
 }
 if strconv.IntSize == 64 {
  f64()
 }
}

func f32() {
 fmt.Println("I am 32-bit")
}

func f64() {
 fmt.Println("I am 64-bit")
}

I am 64-bit


fn main() {
    match std::mem::size_of::<&char>() {
        4 => f32(),
        8 => f64(),
        _ => {}
    }
}

fn f32() {
    println!("I am 32-bit");
}

fn f64() {
    println!("I am 64-bit");
}

I am 64-bit


参考资料

[1]

Golang vs. Rust: Which Programming Language To Choose in 2023?: https://www.trio.dev/blog/golang-vs-rust

本文由 mdnice 多平台发布

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/47344.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【数据结构】实验四:循环链表

实验四 循环链表 一、实验目的与要求 1&#xff09;熟悉循环链表的类型定义和基本操作&#xff1b; 2&#xff09;灵活应用循环链表解决具体应用问题。 二、实验内容 题目一&#xff1a;有n个小孩围成一圈&#xff0c;给他们从1开始依次编号&#xff0c;从编号为1的小孩开…

【项目开发】商城 - 三级分类 - 简单笔记

目录标题 后端业务类实体类 前端最终实现效果排序变化批量删除 后端 业务类 // 省略其他简单的CRUDOverridepublic List<CategoryEntity> listWithTree() {// 1、查出所有分类List<CategoryEntity> list baseMapper.selectList(null);// 2. 找出所有的一级分类Li…

数据库监控工具-PIGOSS BSM

PIGOSS BSM 运维监控系统的重要功能之一是数据库监控&#xff0c;它能够帮助数据库管理员(DBA)和系统管理员监控包含Oracle、SQL Server、MySQL、DB2、PostgreSql、MongoDB、达梦、南大通用、人大金仓、神州通用等多种类异构型的数据库环境。PIGOSS BSM通过执行数据库查询来采集…

【Spring Cloud Alibaba】限流--Sentinel

文章目录 概述一、Sentinel 是啥&#xff1f;二、Sentinel 的生态环境三、Sentinel 核心概念3.1、资源3.2、规则 四、Sentinel 限流4.1、单机限流4.1.1、引入依赖4.1.2、定义限流规则4.1.3、定义限流资源4.1.4、运行结果 4.2、控制台限流4.2.1、客户端接入控制台4.2.2、引入依赖…

基于深度学习的CCPD车牌检测系统(PyTorch+Pyside6+YOLOv5模型)

摘要&#xff1a;基于CCPD数据集的高精度车牌检测系统可用于日常生活中检测与定位车牌目标&#xff0c;利用深度学习算法可实现图片、视频、摄像头等方式的车牌目标检测识别&#xff0c;另外支持结果可视化与图片或视频检测结果的导出。本系统采用YOLOv5目标检测模型训练数据集…

【Spring篇】初识 Spring IoC 与 DI

目录 一. Spring 是什么 ? 二. 何为 IoC ? 三. 如何理解 Spring IoC ? 四. IoC 与 DI 五 . 总结 一. Spring 是什么 ? 我们通常所说的 Spring 指的是 Spring Framework&#xff08;Spring 框架&#xff09;&#xff0c;它是⼀个开源框架&#xff0c;有着活跃⽽ 庞⼤…

逻辑回归概述

逻辑回归介绍 1. 逻辑回归的应用场景 逻辑回归(Logistic Regression)是机器学习中的 一种分类模型 ,逻辑回归是一种分类算法,虽然名字中带有回归。由于算法的简单和高效,在实际中应用非常广泛 广告点击率是否为垃圾邮件是否患病信用卡账单是否会违约 逻辑回归就是解决二…

day14 | 100.二叉树的最大深度 111.二叉树的最小深度 222.完全二叉树的节点个数

文章目录 一、二叉树的最大深度二、二叉树的最小深度三、完全二叉树的节点数 一、二叉树的最大深度 100.二叉树的最大深度 因为题给出的高度和深度是一样的&#xff0c;所以求得结果都能过。 class Solution { public:int getHeight(TreeNode *node){if (node nullptr)retu…

Pytest学习教程_基础知识(一)

前言 pytest是一个用于编写和执行Python单元测试的框架。它提供了丰富的功能和灵活性&#xff0c;使得编写和运行测试变得简单而高效。 pytest的一些主要特点和解释如下&#xff1a; 自动发现测试&#xff1a;pytest会自动查找以"test_"开头的文件、类和函数&#x…

腾讯 SpringBoot 高阶笔记,限时开源 48 小时,真香警告

众所周知&#xff0c;SpringBoot 最大的一个优势就是可以进行自动化配置&#xff0c;简化配置&#xff0c;不需要编写太多的 xml 配置文件&#xff1b;基于 Spring 构建&#xff0c;使开发者快速入门&#xff0c;门槛很低&#xff1b;SpringBoot 可以创建独立运行的应用而不需要…

【学习笔记】目标跟踪领域SOTA方法比较

目录 前言方法1 TraDeS:2 FairMOT:3 SMILEtrack:4 ByteTrack: 前言 常用于行人跟踪的多目标跟踪数据集包括&#xff1a;MOT 15/16/17/20、PersonPath22等… 为更好比较现有SOTA算法的检测性能&#xff0c;本博客将针对在各数据集上表现较优的算法模型进行介绍。&#xff08;表…

ip校园广播音柱特点

ip校园广播音柱特点IP校园广播音柱是一种基于IP网络技术的音频播放设备&#xff0c;广泛应用于校园、商业区、公共场所等地方。它可以通过网络将音频信号传输到不同的音柱设备&#xff0c;实现远程控制和集中管理。IP校园广播音柱具备以下特点和功能&#xff1a;1. 网络传输&am…

SSM框架 基础

1.数据库 2.工程 3.pom 4.web.xml 5.spring配置文件头部 6.实体类 7.StudentMapper接口 8. StudentMapper.xml 9.StudentService 10. StudentServiceImpl 11.StudentController 实战 查询所有 StudentMapper StudentService StudentServiceImpl StudentMapper.xml Stude…

效率与质量兼备的6个设计工具!

今天本文为大家推荐的这6个设计工具&#xff0c;将帮助设计师实现高效工作&#xff0c;同时也更好地展示自己的创作力&#xff0c;一起来看看吧&#xff01; 1、即时设计 即时设计是一款国内的设计工具&#xff0c;它为设计师提供了非常多实用的设计功能和精致的设计素材&…

TCP状态转换图

TCP状态转换图 了解TCP状态转换图可以帮助开发人员查找问题. 说明: 上图中粗线表示主动方, 虚线表示被动方, 细线部分表示一些特殊情况, 了解即可, 不必深入研究. 对于建立连接的过程客户端属于主动方, 服务端属于被动接受方(图的上半部分) 而对于关闭(图的下半部分), 服务端…

day41-Verify Account Ui(短信验证码小格子输入效果)

50 天学习 50 个项目 - HTMLCSS and JavaScript day41-Verify Account Ui&#xff08;短信验证码小格子输入效果&#xff09; 效果 index.html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name&qu…

【西安交通大学】:融合传统与创新的学府之旅

【西安交通大学】&#xff1a;融合传统与创新的学府之旅 引言历史与发展学校特色学科优势院系专业校园环境与设施学生生活与社团活动校友荣誉与成就未来发展展望总结&#x1f340;小结&#x1f340; &#x1f389;博客主页&#xff1a;小智_x0___0x_ &#x1f389;欢迎关注&…

Linux基础以及常用命令

目录 1 Linux简介1.1 不同应用领域的主流操作系统1.2 Linux系统版本1.3 Linux安装1.3.1 安装VMWare1.3.2 安装CentOS镜像1.3.3 网卡设置1.3.4 安装SSH连接工具1.3.5 Linux和Windows目录结构对比 2 Linux常用命令2.0 常用命令&#xff08;ls&#xff0c;pwd&#xff0c;cd&#…

你说你会Java手动锁,但你会这道题吗???

按照这个格式输出你会吗&#xff1f;&#xff1f;&#xff1f; 你说你不会&#xff0c;接下来认真看认真学了。 1.首先引入原子类。AtomicInteger num new AtomicInteger(0); 什么是原子类&#xff1f; 就是可以保证线程安全的原子操作的数据类型。 有什么作用&#xff1f;…

2.2 模型与材质基础

一、渲染管线与模型基础 1. 渲染管线 可编程阶段&#xff08;蓝色区域&#xff09;&#xff1a; 1顶点着色器 2几何着色器 3片元着色器 2. 模型的实现原理 UV&#xff1a;在建模软件中&#xff0c;进行UV展开&#xff0c;UV会放在一个横向为U纵向为V&#xff0c;范围&#xff0…
最新文章