# -*- coding: utf-8 -*-
"""
Python Version: 3.5
Created on Thu May 11 17:00:47 2017
E-mail: Eric2014_Lv@sjtu.edu.cn
@author: DidiLv
"""
# 数学的函数
import numpy as np
x = np.array([[1,2],[3,4]])
# 计算所有的数组值
print(np.sum(x))
# 计算矩阵的列
print(np.sum(x, axis=0))
# 计算矩阵的行
print(np.sum(x, axis=1))
# python还是跟matlab有关的,是按列排序的。
# 当然可以有更多的延伸,都是数学的其他函数
# https://docs.scipy.org/doc/numpy/reference/routines.math.html
x = np.array([[1,2], [3,4]])
print(x) # 输出 "[[1 2]
# [3 4]]"
print(x.T) # 输出 "[[1 3]
# [2 4]]"
# Note that taking the transpose of a rank 1 array does nothing:
v = np.array([1,2,3])
print(v) # 输出 "[1 2 3]"
print(v.T) # 输出 "[1 2 3]" 数组还是数组没有列的概念啊!
# 更多的延伸,类似reshape之类的,可以详情看以下链接
# https://docs.scipy.org/doc/numpy/reference/routines.array-manipulation.html
Python Numpy Tutorials: 数组中数学函数及变形(reshape)
最新推荐文章于 2024-05-07 09:56:58 发布