码迷,mamicode.com
首页 > 其他好文 > 详细

Numpy 学习

时间:2019-11-13 22:18:56      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:imp   options   设置   lse   numbers   矩阵   精度   change   orm   

题意描述

Time fies so fast ~ there is no time left for you to sad.

(#~# my poor english)
import numpy as np
import torch
arr = np.arange(0, 10)
out = np.where(arr%2==0, 0, arr)

# repeat, tile
arr = np.array([1, 2, 3])
out1 = np.hstack((arr.repeat(3), np.tile(arr, 3)))

a = np.arange(6).reshape(-1, 3)
b = np.full((2,3), 1)
# print(np.r_[a, b])
# print(np.c_[a, b])

# r: 矩阵上下相加, c:左右相加
a = np.arange(3)
b = np.arange(3)*(-1)
# print(np.r_[a, b])
# print(np.c_[a, b])

# the same numbers in (a, b)
a = np.array([1,2,3,2,3,4,3,4,5,6])
b = np.array([7,2,10,2,7,4,9,4,9,8])
# print(np.intersect1d(a, b))

# the numbers in a but not in b
a = np.array([1,2,3,4,5])
b = np.array([5,6,7,8,9])
# print(np.setdiff1d(a, b))

a = np.array([1,2,3,2,3,4,3,4,5,6])
b = np.array([7,2,10,2,7,4,9,4,9,8])
# print(np.where(a==b))
# print(np.where([True, True, False, False]))

# condition
a = np.array([2, 6, 1, 9, 10, 3, 27])
# a[np.where( (5<=a) & (a<=10 ))]
# print(a[(5<=a) & (a<=10 )])

# exchange column
# reverse  row & column
arr = np.arange(9).reshape(3, 3)
# print(arr[:, [1, 0, 2]])
# print(arr[::-1])
# print(arr[:,::-1])

# Create a 2D array of shape 5x3 to contain random decimal numbers between 5 and 10.
# print(np.random.uniform(5, 10, (2,2)))
# print(np.random.random((2,2))) # 范围(0,1)
# print(np.random.randint(5, 10, (2,2))) # int

# 设置精度
# np.set_printoptions(3)

# 设置是否科学计数法
X = np.random.random((3, 3))/1e3
# np.set_printoptions(suppress=False)
# print(X)

# 设置打印个数
a = np.arange(10)
# print(a)
# np.set_printoptions(threshold=6)
# print(a)

Numpy 学习

标签:imp   options   设置   lse   numbers   矩阵   精度   change   orm   

原文地址:https://www.cnblogs.com/xidian-mao/p/11853396.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!