简体   繁体   English

在python中声明一个空数组

[英]Declare a empty array in python

I'm changing python code where the value for settings that are declared in the python code are read from a json file the main question is one of the setting values is an array of strings我正在更改 python 代码,其中从 json 文件中读取在 python 代码中声明的设置值,主要问题是设置值之一是字符串数组

Example (json file):示例(json 文件):

"list_of_names": {"names": ["Peter", "James"]} and i´m trying not to declare any value so it will be: "list_of_names": {[]}

When I read this value on the python code example: list_of_names(names=Ilist["names"]) , I need that he accept the empty array with no value, and move to the next setting.当我在 python 代码示例中读取此值时: list_of_names(names=Ilist["names"]) ,我需要他接受没有值的空数组,然后转到下一个设置。 How can I implement this?我该如何实施?

import numpy as np

# Create an empty array
x = np.empty((3,4))

print(x)

# Create a full array
y = np.full((3,3),6)

print(y)

This is the Code to create an empty array in pyhton..这是在 pyhton 中创建空数组的代码。

And the use of numpy as np is this:使用 numpy 作为 np 是这样的:

  1. numpy is a general-purpose array-processing package. numpy 是一个通用的数组处理包。 It provides a high-performance multidimensional array object, and tools for working with these arrays.它提供了一个高性能的多维数组对象,以及用于处理这些数组的工具。

  2. x=np.empty((3,4)) this statement is used to create an array with the size of (3,4) and the values of an array will be empty. x=np.empty((3,4))这个语句用于创建一个大小为 (3,4) 的数组,数组的值将为空。 and print(x) will print the Values of an Array that is Garbage Value will be Printedprint(x)将打印一个数组的值,即垃圾值将被打印

  3. y = np.full((3,3),6) this statement is used to crate an array with the size of (3,3) and the value of an array will be 6. and the print(y) statement will print the values of an Array y = np.full((3,3),6)此语句用于创建一个大小为 (3,3) 且数组值为 6 的数组y = np.full((3,3),6) print(y)语句将打印数组的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM