在 python 中,与数据类型相关函数及属性有三个: 名称 作用 type() 返回参数的数据类型 dtype() 返回数组中元素的数据类型 astype() 对数据类型进行转换 实例: import numpy as np a = np.arange(5) type(a) Out[4]: num ...
分类:
其他好文 时间:
2020-07-19 17:56:34
阅读次数:
57
import numpy as npa = np.arange(6).reshape(2,3)b = np.random.randint(10,20,size=(4,3))#concatenate(array_list,axis=0/1) 沿着指定axis进行数组合并 0为行,1为列,默认为0#np ...
分类:
编程语言 时间:
2020-07-04 22:32:35
阅读次数:
111
x=np.arange(1,13,1) y=np.array([17, 19, 21, 28, 33, 38, 37, 37, 31, 23, 19, 18 ]) plt.plot(x,y) plt.show() 可以看出温度是以周期为12的正弦函数 #构建函数y=a*sin(x*pi/6+b)+c ...
分类:
其他好文 时间:
2020-07-02 13:18:06
阅读次数:
68
题目链接:two-num 思路一:两层for循环暴力求解,结果超时 1 def twoSum(nums,target):#使用二维数组 2 for i in range(len(nums)): 3 for j in np.arange(i+1,len(nums)): 4 if(nums[i] + n ...
分类:
其他好文 时间:
2020-06-29 17:11:10
阅读次数:
41
def getRandomIndex(n, x): # 索引范围为[0, n),随机选x个不重复,注意replace=False才是不重复,replace=True则有可能重复 index = np.random.choice(np.arange(n), size=x, replace=False) ...
分类:
其他好文 时间:
2020-06-22 23:20:09
阅读次数:
56
# Series 以为,带标签数组 # DataFrame二维,Series容器 import string import pandas as pd import numpy as np # t = pd.Series(np.arange(10), index=list(string.ascii_u ...
分类:
其他好文 时间:
2020-06-22 23:16:15
阅读次数:
66
import numpy a=numpy.arange(1,25).reshape(8,3) #对二维进行数组转置 b=numpy.transpose(a) c=a.transpose() d=a.T #print(d) print('对于三维a[i][j][k]进行转置,默认的将i和k交换,j位置 ...
分类:
编程语言 时间:
2020-06-19 11:56:41
阅读次数:
45
NumPy中,可以通过指定数值范围创建ndarray数组。 numpy.arange 要使用指定区间均匀分布的数值创建数组,可以使用arange函数。 语法如下所示: numpy.arange(start, stop, step, dtype) 参数: start: 区间开始值。默认值是0。 sto ...
分类:
编程语言 时间:
2020-06-19 10:26:47
阅读次数:
78
import numpy a=numpy.arange(10) #索引访问,和字符串索引一样 print(a[-3]) print(a[2]) #切片访问 print(a[:]) print(a[3:4]) print(a[1:7:2]) print(a[::-1]) ...
分类:
编程语言 时间:
2020-06-17 10:28:20
阅读次数:
45
import numpy a=numpy.arange(1,10,2,dtype=float) #1指初值,2值终值,2指步长 b=numpy.sqrt(a) #对a数组里面的每个元素进行开平方 ...
分类:
编程语言 时间:
2020-06-15 22:54:47
阅读次数:
58