当前位置: 首页 > news >正文

济宁网站网站建设完成网站开发需要什么样技术

济宁网站网站建设,完成网站开发需要什么样技术,湖南网站建设工作室,在线做ppt的网站有时候需要对某一组数组的数据进行判断是否 递增 的场景,比如我在开发一些体育动作场景下,某些肢体动作是需要持续朝着垂直方向向上变化,那么z轴的值是会累增的。同理,逆向考虑,递减就是它的对立面。 下面是查找总结到…

有时候需要对某一组数组的数据进行判断是否 递增 的场景,比如我在开发一些体育动作场景下,某些肢体动作是需要持续朝着垂直方向向上变化,那么z轴的值是会累增的。同理,逆向考虑,递减就是它的对立面。

下面是查找总结到的所有方式,如有补充可以评论区提出。

资料参考来源: Check if list is strictly increasing

1. zip() and all()

  • Code:
test_list = [1, 4, 5, 7, 8, 10]
# Using zip() and all() to
# Check for strictly increasing list
res = all(i < j for i, j in zip(test_list, test_list[1:]))
print(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(n), n是数组的长度。

2. reduce and lambda

  • Code:
import functoolstest_list = [1, 4, 5, 7, 8, 10]
res = bool((lambda list_demo: functools.reduce(lambda i, j: j ifi < j else 9999, list_demo) != 9999)(test_list))print(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(n), n是数组的长度。

3. itertools.starmap() + zip() + all()

  • Code:
import itertoolstest_list = [1, 4, 5, 7, 8, 10]
res = all(itertools.starmap(operator.le, zip(test_list, test_list[1:])))print(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(n), n是数组的长度。

4. sort() and extend()

  • Code:
test_list = [1, 4, 5, 7, 8, 10]
res = False
new_list = []
new_list.extend(test_list)
test_list.sort()if new_list == test_list:res = Trueprint(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(nlogn), 这里是sort()的时间复杂度

5. Use stacks

栈是一种后进先出的数据结构(Last in, first out)。

  • Code:
def is_strictly_increasing(lst):stack = []for i in lst:if stack and i <= stack[-1]:return Falsestack.append(i)return Truetest_list = [1, 4, 5, 7, 8, 10]
print(is_strictly_increasing(test_list))  # Truetest_list = [1, 4, 5, 7, 7, 10]
print(is_strictly_increasing(test_list))  # False

时间复杂度: O(n),原数组被遍历了一遍
空间复杂度: O(n),栈可能要存储全部的n个原数组元素

6. numpy()

  • Code:
import numpy as npdef is_increasing(lst):# Converting input list to a numpy arrayarr = np.array(lst)# calculate the difference between adjacent elements of the arraydiff = np.diff(arr)# check if all differences are positive# using the np.all() functionis_increasing = np.all(diff > 0)# return the resultreturn is_increasing# Input list
test_list = [1, 4, 5, 7, 8, 10]# Printing original lists
print("Original list : " + str(test_list))result = is_increasing(test_list)print(result)
# True

时间复杂度: O(n)

7. itertools.pairwise() and all()

这里面就等于使用 pairwise() 替代了之前的 zip(list, list[1:])

  • Code:
from itertools import pairwise# Function
def is_strictly_increasing(my_list):# using pairwise method to iterate through the list and# create pairs of adjacent elements.# all() method checks if all pairs of adjacent elements# satisfy the condition i < j, where i and j# are the two elements in the pair.if all(a < b for a, b in pairwise(my_list)):return Trueelse:return False# Initializing list
test_list = [1, 4, 5, 7, 8, 10]# Printing original lists
print("Original list : " + str(test_list))# Checking for strictly increasing list
# using itertools pairwise() and all() method
res = is_strictly_increasing(test_list)# Printing the result
print("Is list strictly increasing ? : " + str(res))
  • Output:
Original list : [1, 4, 5, 7, 8, 10]
Is list strictly increasing ? : True

时间复杂度: O(n)

http://www.yayakq.cn/news/815055/

相关文章:

  • 做网站用php西安市住房和城乡建设局官网
  • 电影网站做cpadirectory wordpress
  • 手表电商网站专业网络推广公司排名
  • 给网站做seo诊断零售管理系统哪个软件好
  • 长沙百度网站推广优化汉口网站优化
  • 杭州餐饮团购网站建设渭南网站建设远景
  • 小学生摘抄新闻安阳企业网站优化外包
  • 如何做网站关键词动态和静态网站的区别
  • 跟京东类似的网站西安电商平台网站建设
  • 新手如何做网站创意设计服务是什么
  • 观澜小学网站建设wordpress数据库访问优化
  • 东营网站建设优化seo怎么去优化
  • 国外免费推广网站免费自己建网站
  • 网站开发用什么语言比较流行wordpress 查看用户密码
  • 给领导发网站建设可行性方案邮件怎么写中铁建设集团内网登录
  • 网站建设网上商城厦门建设局公维金网站
  • 临安建设规划局网站仪表东莞网站建设
  • 株洲网站排名优化价格搜狗推广做网站要钱吗
  • 东莞南城网站制作公司贵州住房和建设厅网站
  • 网站建设合同中英文模板网站开发未按合同约定开发时间完工
  • 营销型网站要素企业微信小程序制作
  • 资源下载站wordpress主题怎么查有做网站的公司
  • php做网站麻烦吗wordpress直播平台
  • 建站塔山双喜专业做招聘网站
  • 关注江苏建设厅网站南阳高质量建设大城市网站
  • 网站上的图片做多大站长工具黄
  • 成都官方网站建设中小型企业网站优化案例
  • 营销型网站设计如何免费发布广告
  • 网站主页面布局怎么做互联网企业有哪些行业
  • 如何在网站做qq群链接seo网站优化推广怎么做