使用 NumPy 在给定列表中查找数字的倍数
在这个程序中,我们将找到给定数字的倍数存在的索引位置。我们将同时使用Numpy和Pandas库来完成这项任务。
算法
Step 1: Define a Pandas series. Step 2: Input a number n from the user. Step 3: Find the multiples of that number from the series using argwhere() function in the numpy library.
示例代码
import numpy as np
listnum = np.arange(1,20)
multiples = []
print("NumList:\n",listnum)
n = int(input("输入要查找倍数的数字: "))
for num in listnum:
if num % n == 0:
multiples.append(num)
print("Multiples of {} are {}".format(n, multiples))输出结果NumList: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19] 输入要查找倍数的数字: 5 Multiples of 5 are [5, 10, 15]
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短