radius = np.r_[0:1:50j] x = np.array([r * np.cos(theta)forrinradius]) y = np.array([r * np.sin(theta)forrinradius]) z = np.array([drumhead_height(1,1, r, theta,0.5)forrinradius]) fig = plt.figure() ax = fig.add_...
4. 函数 定义:函数是组织好的,可重复使用,用于实现单一或者相关联功能的代码段。 在Python 中既有内建函数,比如print()、sum(),也可以用户自定义函数。 4.1 定义函数 自定义一个函数需要遵守一些规则: 函数代码块必须以def关键词开头,然后是函数标识符名称(函数名)和圆括号(); 圆括号内部用于定义参数,并且传入...
创建数据字典 In [1]:dict()Out[1]: {}In [2]:dict(a='a',b='b')Out[2]: {'a':'a','b':'b'}In [3]:dict(zip(['a','b'],[1,2]))Out[3]: {'a':1,'b':2}In [4]:dict([('a',1),('b',2)])Out[4]: {'a':1,'b':2} 19 一键查看对象所有方法 不带参数时返...
执行程序后文件夹增加了“example.xlsx”: 此时表格是空的: 2. xlwings 打开已存在的 Excel 文档 现有表格长这样: 运行程序: # 3.4.3 xlwings 打开已存在的Excel文件def fun3_4_3():# 新建Excle 默认设置:程序可见,只打开不新建工作薄,屏幕更新关闭app = xw.App(visible=True, add_book=False) app.displ...
Example #8Source File: LongShortTermMemoryNetworks.py From DeepLearningTutorial with MIT License 5 votes def initialize_LSTM(self): hyp = np.array([]) Q = self.hidden_dim # Forget Gate U_f = -np.sqrt(6.0/(self.X_dim+Q)) + 2.0*np.sqrt(6.0/(self.X_dim+Q))*np.random.rand(...
Example #6Source File: utils.py From DeepRobust with MIT License 5 votes def to_tensor(adj, features, labels=None, device='cpu'): """Convert adj, features, labels from array or sparse matrix to torch Tensor. Parameters --- adj : scipy.sparse.csr_matrix the adjacency matrix. features ...
1#-*- coding: utf-8 -*-2#---34"""5# Author : chu ge6# Function: Numpy7#8"""910#---11'''12# ---13# 导入模块14# 1.系统库15# 2.第三方库16# 3.相关定义库17# ---18'''19#1.系统库、20importsys21importos2223#2.第三方库24importnumpy as np25fromscipyimportlinalg26importpa...
repeat name array map dtype 29. divmod to_frame unique ravel searchsorted 30. hasnans is_unique is_monotonic cat argmin 31. >>> 32. >>> for i,f in enumerate(set(A)&set(B),1): 33. print(f'{f:18}',end='' if i%5 else '\n') 34. 35. 36. lt get reorder_levels ...
#查看 city 列中的唯一值 df['city'].unique() array(['Beijing ', 'SH', ' guangzhou ', 'Shenzhen', 'shanghai', 'BEIJING '], dtype=object) 查看数据表数值 Python 中的 Values 函数用来查看数据表中的数值。以数组的形式返回,不包含表头信息。 #查看数据表的值 df.values array([[1001, Timest...
是重新创建一个DataFrame,直接把df.a所有可能取值作为新dataframe的列,index调整为[0],注意类型必须是数组类型(array-like 或者 Index),两个轴确定后,data填充数据域。 In[116]: dict(zip(df.a,df.val)) Out[116]: {'apple1': 1.0, 'apple2': 2.0, 'apple3': 3.0, 'apple4': 4.0, 'apple5':...