使用 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]
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短