Python终极学习秘籍-7_-NumPy-1.pdfVIP

  • 1
  • 0
  • 约5.9千字
  • 约 1页
  • 2024-08-14 发布于广西
  • 举报

PythonCheatSheet:NumPy

“A​puzzleadaytolearn,code,andplay​”→Visit​

Name

Description

Example

a.shape

TheshapeattributeofNumPyarrayakeepsatupleof

a=np.array([[​1​,​2​],[​1​,​1​],[​0​,​0​]])

integers.Eachintegerdescribesthenumberofelementsof

print(np.shape(a))​#(3,2)

theaxis.

a.ndim

Thendimattributeisequaltothelengthoftheshapetuple.

print(np.ndim(a))​#2

*

Theasterisk(star)operatorperformstheHadamardproduct,

a=np.array([[​2​,​0​],[​0​,​2​]])

i.e.,multipliestwomatriceswithequalshapeelement-wise.

b=np.array([[​1​,​1​],[​1​,​1​]])

print(a*b)​#[[20][02]]

np.matmul(a,b),a@b

Thestandardmatrixmultiplicationoperator.Equivalenttothe

print(np.matmul(a,b))

@operator.

#[[22][22]]

np.arange([start,]stop,Createsanew1Dnumpyarraywithevenlyspacedvalues

print(np.arange(​0​,​10​,​2​))

[step,])

#[02468]

np.linspace(start,stop,Createsanew1Dnumpyarraywithevenlyspreadelements

print(np.linspace(​0​,​10​,​3​))

num=​50​)

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档