Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. คืนค่า gradient ของอาร์เรย์ N มิติตาม axis 1 ใน Python

    ภาพรวม ใช้ numpy.gradient() คำนวณ gradient ของอาร์เรย์ N มิติ ตาม axis=1 (แนวนอน/คอลัมน์) ใช้ central differences order 2 ที่จุดภายใน และ one-sided differences ที่ขอบเขต ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. สร้างอาร์เรย์ 2D float arr = np.array([[20, 35, 57], [70, 85, 120]], dtyp

  2. ทดสอบว่า datatype คล้ายกันขนาดต่างๆ ไม่ใช่ subtype ของกันและกันใน Python

    ภาพรวม ใช้ numpy.issubdtype() ตรวจสอบว่า similar data types ขนาดต่างๆ ไม่ใช่ subtype ของกันและกัน ทดสอบทั้ง float และ int types ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. ทดสอบ float types print(Result..., np.issubdtype(np.float32, np.float64)) print(Result..., np.issubdtype(np.float64

  3. ทดสอบว่า int datatype ขนาดต่างๆ ไม่ใช่ subtype ของกันและกันใน Python

    ภาพรวม ใช้ numpy.issubdtype() ตรวจสอบว่า integer data types ขนาดต่างๆ (int16, int32, int64) ไม่ใช่ subtype ของกันและกัน ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. ทดสอบ issubdtype() คู่ต่อคู่ print(Result..., np.issubdtype(np.int16, np.int32)) print(Result..., np.issubdtype(np.int32, n

  4. ทดสอบว่า float datatype ขนาดต่างๆ ไม่ใช่ subtype ของกันและกันใน Python

    ภาพรวม ใช้ numpy.issubdtype() ตรวจสอบว่า float data types ขนาดต่างๆ (float16, float32, float64) ไม่ใช่ subtype ของกันและกัน ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. ทดสอบ issubdtype() คู่ต่อคู่ print(Result..., np.issubdtype(np.float16, np.float32)) print(Result..., np.issubdtype(np.

  5. ตรวจสอบว่า type ใน argument แรกเป็น subclass ของ argument ที่สองใน Python

    ภาพรวม ใช้ numpy.issubsctype() ตรวจสอบว่า type ใน argument แรกเป็น subclass ของ argument ที่สอง ทั้งสอง argument เป็น datatypes ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. ทดสอบ issubsctype() กรณีต่างๆ print(Result..., np.issubsctype(np.float16, np.float32)) print(Result..., np.issubsct

  6. หา Kronecker product ของอาร์เรย์ 4 มิติ และ 3 มิติใน Python

    ภาพรวม ใช้ numpy.kron() คำนวณ Kronecker product ของอาร์เรย์ 4D และ 3D สร้าง composite array จาก blocks ของ array ที่สอง scaled โดย array แรก ถ้า a.shape = (r₀,r₁,..,rₙ) และ b.shape = (s₀,s₁,..,sₙ) ผลลัพธ์ shape = (r₀s₀, r₁s₁, ..., rₙsₙ) ฟังก์ชันสมมติ dimensions เท่ากัน จะ prepend ด้วย 1 ให้เท่ากัน

  7. คืนค่า Cholesky decomposition ในพีชคณิตเชิงเส้นด้วย Python

    ภาพรวม ใช้ numpy.linalg.cholesky() คืน Cholesky decomposition L × Lᴴ ของ square matrix a โดย L เป็น lower-triangular และ .ᴴ คือ conjugate transpose a ต้องเป็น Hermitian และ positive-definite (ไม่ตรวจสอบอัตโนมัติ) ใช้เฉพาะ lower-triangular และ diagonal elements คืนแค่ L พารามิเตอร์ a: เมทริกซ์ Her

  8. คำนวณ eigenvalues ของเมทริกซ์ complex Hermitian หรือ real symmetric ใน Python

    ภาพรวม ใช้ numpy.linalg.eigvalsh() คำนวณ eigenvalues ของเมทริกซ์ complex Hermitian หรือ real symmetric คืนค่า eigenvalues เรียงจากน้อยไปมาก ตาม multiplicity พารามิเตอร์ a: เมทริกซ์ complex หรือ real ที่ต้องการ eigenvalues UPLO (optional): L (default, lower triangular) หรือ U (upper triangular) ใช

  9. คืนค่า Norm ของเมทริกซ์หรือเวกเตอร์ในพีชคณิตเชิงเส้นด้วย Python

    ภาพรวม ใช้ LA.norm() (numpy.linalg.norm) คำนวณ norm ของเมทริกซ์หรือเวกเตอร์ รองรับหลาย order (ord) พารามิเตอร์ x: อาร์เรย์อินพุท (1-D หรือ 2-D ถ้า axis=None) ord (optional): order ของ norm (default None = 2-norm สำหรับ vector, Frobenius สำหรับ matrix) axis (optional): axis สำหรับ vector norms หรื

  10. คำนวณ condition number ของเมทริกซ์ด้วย Frobenius norm ใน Python

    ภาพรวม ใช้ numpy.linalg.cond() คำนวณ condition number รองรับ 7 norms พารามิเตอร์ p = fro หมายถึง Frobenius norm (รากที่สองของผลรวมกำลังสองของทุก element) ขั้นตอนการทำงาน 1. นำเข้าไลบรารี import numpy as np from numpy import linalg as LA 2. สร้างเมทริกซ์ 3x3 arr = np.array([[1, 1, 0], [1, 0, 1], [

  11. เปลี่ยนส่วนจริง (real part) ของจำนวนเชิงซ้อนใน Python

    ภาพรวม ใช้ numpy.real() ดึงส่วนจริงของจำนวนเชิงซ้อน คืนค่า real component ถ้า val เป็น real ใช้ type ของ val ถ้า val มี complex elements คืน float ยังสามารถเปลี่ยนส่วนจริงได้โดย assignment ผ่าน array.real = value พารามิเตอร์ val: อาร์เรย์อินพุท ขั้นตอนการทำงาน 1. นำเข้าไลบรารี import numpy as n

  12. คำนวณ n-th discrete difference สำหรับ unsigned integer arrays ใน Python

    ภาพรวม ใช้ numpy.diff() คำนวณ n-th discrete difference ตาม axis ที่กำหนด first difference: out[i] = a[i+1] - a[i] higher differences คำนวณซ้ำด้วย diff recursively สำคัญ: สำหรับ unsigned integer arrays ผลลัพธ์ก็จะเป็น unsigned ด้วย (underflow กลายเป็นค่ามาก) พารามิเตอร์ a: อาร์เรย์อินพุท n (optio

  13. คืนค่า gradient ของอาร์เรย์ N มิติใน Python

    ภาพรวม ใช้ numpy.gradient() คำนวณ gradient ของอาร์เรย์ N มิติ ใช้ central differences order 2 ที่จุดภายใน และ one-sided differences ที่ขอบเขต ผลลัพธ์มี shape เดียวกับ input คืน list ของ ndarrays ตรงกับ derivatives ตามแต่ละ dimension พารามิเตอร์ f: อาร์เรย์ N มิติ samples ของ scalar function varar

  14. สร้าง Pseudo Vandermonde matrix ของ Hermite polynomial และจุด x, y, z complex array ใน Python

    ภาพรวม ใช้ numpy.polynomial.hermite.hermvander3d() สร้าง pseudo-Vandermonde matrix ของ Hermite polynomial สำหรับจุดตัวอย่าง x, y, z พารามิเตอร์ x, y, z: อาร์เรย์พิกัดจุด ทุกตัวต้องมี shape เหมือนกัน dtype จะแปลงเป็น float64 หรือ complex128 deg: list ของ maximum degrees [x_deg, y_deg, z_deg] ขั้

  15. คืนค่า scaled companion matrix ของ Hermite series coefficients 1-D array ใน Python

    ภาพรวม ใช้ numpy.polynomial.hermite.hermcompanion() คืน scaled companion matrix ของ 1-D array ของ Hermite polynomial coefficients basis polynomials ถูก scale ให้ companion matrix เป็น symmetric (เมื่อ c เป็น Hermite basis) ให้ eigenvalue estimates ดีกว่า และ eigenvalues จะเป็น real ถ้าใช้ numpy.lin

  16. คืนค่า cross product ของสองเวกเตอร์ (หรืออาร์เรย์ของเวกเตอร์) ใน Python

    ภาพรวม ใช้ numpy.cross() คำนวณ cross product ของสองเวกเตอร์ คืนค่า c เป็น vector cross product(s) พารามิเตอร์ a: องค์ประกอบของเวกเตอร์แรก b: องค์ประกอบของเวกเตอร์ที่สอง axisa, axisb, axisc (optional): axis ที่กำหนดเวกเตอร์ (default = last axis) axis (optional): override axisa, axisb, axisc ขั้น

  17. ทำการ integral ตาม axis 1 ด้วยกฎ trapezoidal แบบ composite ใน Python

    ภาพรวม ใช้ numpy.trapz() ทำ integration ตาม axis=1 ด้วย composite trapezoidal rule คืนค่า definite integral ตาม axis แนวนอน ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. สร้างอาร์เรย์ 3x3 arr = np.arange(9).reshape(3, 3) 3. แสดงข้อมูลอาร์เรย์ print(Our Array...\n, arr) print(\nDimensions

  18. ทำการ integral ตาม axis 0 ด้วยกฎ trapezoidal แบบ composite ใน Python

    ภาพรวม ใช้ numpy.trapz() ทำ integration ตาม axis=0 ด้วย composite trapezoidal rule คืนค่า definite integral ของอาร์เรย์ n-D ตาม axis เดียว ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. สร้างอาร์เรย์ 3x3 arr = np.arange(9).reshape(3, 3) 3. แสดงข้อมูลอาร์เรย์ print(Our Array...\n, arr) pri

  19. คืนคำอธิบายสำหรับ data type code ที่กำหนดใน Python

    ภาพรวม ใช้ numpy.typename() คืนคำอธิบาย (description) สำหรับ data type code ที่กำหนด ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. รายการ data type codes arr = [S1, ?, B, D, G, F, I, H, L, O, Q, S, U, V, b, d, g, f, i, h, l, q] 3. แสดงคำอธิบายแต่ละ code for i in arr: print(i,

  20. คืนค่าตัวแทน string ของ scalar dtype ใน Python

    ภาพรวม ใช้ numpy.sctype2char() คืนค่าตัวอักษร (character) ที่แทน scalar dtype ถ้าเป็น scalar dtype จะคืน character ตรงกัน ถ้าเป็น object จะพยายาม infer scalar type แล้วคืน character ขั้นตอนการทำงาน 1. นำเข้า NumPy import numpy as np 2. แสดง string representation ของ scalar types ต่างๆ for i in [n

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:418/451  20-คอมพิวเตอร์/Page Goto:1 412 413 414 415 416 417 418 419 420 421 422 423 424