MATLAB与Numpy常用函数对比及转换指南

需积分: 0 2 下载量 89 浏览量 更新于2024-09-05 收藏 33KB DOCX 举报
"这篇文章主要对比了MATLAB与Python的Numpy库中常用函数的对应关系,旨在帮助将Python代码转换为MATLAB代码的用户。它来源于scipy官网的翻译整理,同时也包含了作者个人的理解和补充。文章强调了Numpy中的array和matrix两个类在处理线性代数和数组操作时的不同之处,包括操作符的使用、向量处理、高维数组处理以及便捷属性。" 在MATLAB和Numpy之间进行转换时,理解两者的核心差异至关重要。Numpy作为Python的数据科学库,其设计目标与MATLAB类似,但也存在一些关键区别。在Numpy中,`array`和`matrix`是两个重要的数据结构,它们各自有特定的应用场景。 1. **操作符的使用**: - `array`: 在`array`对象中,星号`*`用于元素级乘法,相当于MATLAB的点乘。矩阵乘法需要使用`dot()`函数。 - `matrix`: 对于`matrix`对象,星号`*`执行矩阵乘法,类似于MATLAB。而`multiply()`用于元素级乘法,更接近MATLAB的数乘。 2. **向量处理**: - `array`: 一维数组在切片如`A[:,1]`时返回形状为N的一维数组,而不是N×1的矩阵。一维数组的转置不变,保持原有形状。 - `matrix`: 一维数组会被自动转换为1×N或N×1的矩阵,`A[:,1]`会返回一个N×1的矩阵。 3. **高维数组处理**: - `array`: `array`可以处理任意维度的数组,维度数不受限制。 - `matrix`: `matrix`仅支持2维数组,不适用于高维数据处理。 4. **属性(attributes)**: - `array`: 提供`.T`属性用于获取转置。 - `matrix`: 除了`.T`外,还有`.H`(共轭转置)、`.I`(逆矩阵)和`.A`(转化为`array`)等额外属性。 5. **数组构造**: - 在构造数组时,MATLAB和Numpy有不同的语法,MATLAB通常使用冒号`:`进行索引和切片,而Numpy则使用方括号`[]`。 转换MATLAB到Numpy代码时,理解这些基本概念可以帮助你准确地找到等价操作。同时,注意Numpy的灵活性可能要求你在某些情况下使用不同的方法来实现MATLAB中的功能。例如,当你在MATLAB中使用矩阵乘法时,可能需要在Numpy中使用`numpy.dot()`或`@`操作符(Python 3.5及以后版本)。此外,对于数组操作,可能需要使用`reshape`, `transpose`, `broadcasting`等Numpy特性来实现MATLAB的相应功能。 通过熟悉这些差异,开发者可以更好地在两个环境中切换,并有效地利用Numpy的强大功能进行数值计算和数据分析。

n the present research, a hybrid laser polishing technology combining pulsed laser and continuous wave laser was applied to polish the surface of laser directed energy deposition (LDED) Inconel 718 superalloy components. The surface morphology, microstructure evolution and microhardness of the as-fabricated, the single pulsed laser polishing (SPLP) and the hybrid laser polishing (HLP) processed samples were investigated. The results revealed that the as-fabricated sample has a rough surface with sintered powders. In the matrix, the NbC carbide and Cr2Nb based Laves phase array parallel to the build direction and the small γʺ-Ni3Nb particles precipitate in matrix uniformly. The surface roughness of the as-fabricated sample is 15.75 μm which is decreased to 6.14 μm and 0.23 μm by SPLP and HLP processing, respectively. The SPLP processing refines the grains and secondary phase significantly in the remelted layer which is reconstructured with the cellular structure and plenty of substructures. The HLP processing also refines the grain and secondary phase but the secondary phases still exhibit array distribution. In addition, the tangled dislocations pile up along the interface of secondary phases. Compared with the as-fabricated sample, the SPLP processing decreases the surface microhardness but the HLP processing increases the surface microhardness, and the Young's elasticity modulus of surface layer is improved by SPLP and HLP processing to 282 ± 5.21 GPa and 304 ± 5.57 GPa, respectively. 翻译

2023-07-25 上传

马丁路德金的"I have a dream"节选存放在"freedom.txt"中: I have a dream that one day this nation will rise up, live up to the true meaning of its creed: “We hold these truths to be self-evident; that all men are created equal.” I have a dream that one day on the red hills of Georgia the sons of former slaves and the sons of former slave-owners will be able to sit down together at the table of br otherhood. I have a dream that one day even the state of Mississippi, a state sweltering with th e heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice. I have a dream that my four children will one day live in a nation where they will no t be judged by the color if their skin but by the content of their character. I have a dream today. I have a dream that one day down in Alabama with its governor having his lips drippin g with the words of interposition and nullification, one day right down in Alabama li ttle black boys and black girls will be able to join hands with little white boys and white girls as sisters and brothers. I have a dream today. I have a dream that one day every valley shall be exalted, every hill and mountain sh all be made low, the rough places will be made plain, and the crooked places will be made straight, and the glory of the Lord shall be revealed, and all flesh shall see i t together. 编程实现词汇表,计算每一个单词出现的次数,大小写不区分,输出到"dic.txt" 文件保存。

2023-06-01 上传