python: 压缩图片.webp

pip install imageio
    image = imageio.imread("1.jpg")
    imageio.imwrite("output_image.webp", image, "WEBP")

  

 

# 代码示例:使用Python的Keras库构建Autoencoder模型
from keras.models import Model
from keras.layers import Input, Dense

input_img = Input(shape=(784,))
encoded = Dense(128, activation='relu')(input_img)
decoded = Dense(784, activation='sigmoid')(encoded)

autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')

 

    rows, cols = (10, 10)
    # 创建一个真正的二维数组
    F = [[0 for _ in range(cols)] for _ in range(rows)]
    n = int(input('请输入数字:'))
    y = 0

    while y < rows:
        x = 0
        while x < cols:
            for i in range(y, y + n):
                for j in range(x, x + n):
                    if(i<=9 and j<=9):
                        F[i][j] = 1
            x += n * 2  # 用于每个隔一个相同的距离x 的坐标
        y += n * 2  # 用于每个隔一个相同的距离y的坐标
    #打印效果
    for row in F:
        for col in row:
            print(col, end=" ")
        print()

  

 

   rows, cols = (10, 10)
    # 创建一个真正的二维数组
    F = [[0 for _ in range(cols)] for _ in range(rows)]
    n = int(input('请输入数字:'))
    y = 0

    while y < rows:
        x = 0
        while x < cols:
            for i in range(y, min(y + n, rows)):
                for j in range(x, min(x + n, cols)):
                    F[i][j] = 1
            x += n * 2  # 用于每个隔一个相同的距离x 的坐标
        y += n * 2  # 用于每个隔一个相同的距离y的坐标
    #打印效果
    for row in F:
        for col in row:
            print(col, end=" ")
        print()


    letter_array = [
        "JGJGDDAOYD",
        "IDGFHSPOSA",
        "FGDIOSAFSC",
        "INTERNETSO",
        "FJKCOSAFSM",
        "DJSGAPAHDP",
        "HAUSTRFBFU",
        "KDGFUCNSKT",
        "WSJDYCFXDE",
        "ODVFKXJVCR"
    ]

    word = input("请输入单词: ")
    word = word.upper()
    find = False

    if not letter_array or not word:
        print("输入的单词为空或字符串数组为空。")
    else:
        rows = len(letter_array)
        word_length = len(word)

        # 遍历所有行
        for row in letter_array:
            # 在每一行中,从左到右滑动单词长度的窗口
            for start_col in range(len(row) - word_length + 1):
                # 检查当前窗口的字符串是否与单词匹配
                if row[start_col:start_col + word_length] == word:
                    find = True  # 如果在某一行的窗口中找到单词,则返回True
                    break  # 找到单词后立即退出循环
            if find:
                break  # 找到单词后立即退出循环

        if find:
            print(f"单词 '{word}' 存在于字符串数组的行线上。")
        else:
            print(f"单词 '{word}' 不存在于字符串数组的任何行线上。")




    letter_array = [
        "JGJGDDAOYD",
        "IDGFHSPOSA",
        "FGDIOSAFSC",
        "INTERNETSO",
        "FJKCOSAFSM",
        "DJSGAPAHDP",
        "HAUSTRFBFU",
        "KDGFUCNSKT",
        "WSJDYCFXDE",
        "ODVFKXJVCR"
    ]

    word = input("请输入单词: ")
    word = word.upper()
    rows = len(letter_array)
    cols = len(letter_array[0]) if rows > 0 else 0
    word_length = len(word)
    find = False

    # 检查所有可能的起始位置
    for i in range(rows):
        for j in range(cols):
            # 检查当前位置是否在数组的边界内,如果这个单词可以放在对角线上
            if i + word_length <= rows and j + word_length <= cols:
                # 检查单词是否与对角线匹配
                match = True
                for k in range(word_length):
                    if letter_array[i + k][j + k] != word[k]:
                        match = False
                        break
                if match:
                    find = True
                    break  # 找到匹配后立即停止搜索
        if find:
            break  # 找到匹配后立即停止搜索

    if find:
        print(f"单词 '{word}' 存在于字符串数组的对角线上。")
    else:
        print(f"单词 '{word}' 不存在于字符串数组的任何对角线上。")
 

    letter_array = [
        "JGJGDDAOYD",
        "IDGFHSPOSA",
        "FGDIOSAFSC",
        "INTERNETSO",
        "FJKCOSAFSM",
        "DJSGAPAHDP9",
        "HAUSTRFBFU",
        "KDGFUCNSKT",
        "WSJDYCFXDE",
        "ODVFKXJVCR"
    ]

    word = "CAR"
    word = input("please enter word:")
    word = word.upper()
    rows = len(letter_array)
    cols = len(letter_array[0]) if rows > 0 else 0
    find=False
    # 所有可能的index起始位置
    for i in range(rows):
        for j in range(cols):
            # 检查当前位置是否在数组的边界内
            # ,如果这个单词可以放在index上
            if i + len(word) <= rows and j + len(word) <= cols:
                # 检查单词是否与index匹配
                match = True
                for k in range(len(word)):
                    if letter_array[i + k][j + k] != word[k]:
                        match = False
                        break
                if match:
                    find= True
    if find:
        print(f"The word '{word}' exists in the letter array as a diagonal.")
    else:
        print(f"The word '{word}' does not exist in the letter array as a diagonal.")


    letter_array = [
        "JGJGDDAOYD",
        "IDGFHSPOSA",
        "FGDIOSAFSC",
        "INTERNETSO",
        "FJKCOSAFSM",
        "DJSGAPAHDP",
        "HAUSTRFBFU",
        "KDGFUCNSKT",
        "WSJDYCFXDE",
        "ODVFKXJVCR"
    ]




    word = "MPUTER"  # 在一列部分的位置
    word=input("输入要在列中查找的单词")
    # 转换为大写以便与letter_array中的字符进行比较
    word = word.upper()
    find=False
    if not letter_array or not word:
        find= False

    cols = len(letter_array[0])
    rows = len(letter_array)
    word_length = len(word)

    # 遍历所有列
    for j in range(cols):
        # 在每一列中,从顶部到底部滑动单词长度的窗口
        for start_row in range(rows - word_length + 1):
            # 检查当前窗口的字符串是否与单词匹配
            match = True
            for i in range(word_length):
                if letter_array[start_row + i][j] != word[i]:
                    match = False
                    break
            if match:
                find= True  # 如果在某一列的窗口中找到单词,则返回True

    if find:
        print(f"The word Part '{word}' exists in the letter array as a column.")
    else:
        print(f"The word Part '{word}' does not exist in the letter array as a column.")

  

   rows, cols = (10, 10)
    F = [[0 for _ in range(cols)] for _ in range(rows)]
    n = int(input("please number:"))
    y = 0
    while y < rows:
        x = 0
        while x < cols:
            for i in range(y, y + n ):
                for j in range(x, x + n):
                    if i <= 9 and j <= 9:
                        F[i][j] = 1
            x += n * 2
        y += n * 2

    # 打印效果
    for row in F:
        for col in row:
            print(col, end=" ")
        print()


    rows, cols = (10, 10)
    # 创建一个真正的二维数组
    F = [[0 for _ in range(cols)] for _ in range(rows)]
    n = int(input('请输入数字:'))
    y = 0

    while y < rows:
        x = 0
        while x < cols:
            for i in range(y, min(y + n,rows)):
                for j in range(x, min(x + n,cols)):
                    F[i][j] = 1
            x += n * 2  # 用于每个隔一个相同的距离x 的坐标
        y += n * 2  # 用于每个隔一个相同的距离y的坐标
    #打印效果
    for row in F:
        for col in row:
            print(col, end=" ")
        print()

  

posted @ 2024-06-10 23:52  ®Geovin Du Dream Park™  阅读(22)  评论(0编辑  收藏  举报