简体   繁体   中英

Advice for creating a Python 3 numpy array

I'm trying to build an array of products and build material using numpy but I'm having difficulty trying to determine the best layout for the array.

The array will consist of a list of products, raw material, and if a product requires another product for it to be built and list that required products raw material.

Ideally, the user would type in a product name and the program will return the Raw Material needed, and if another product is required.

For example: If I want to build a desk the program would lookup Desk in the array and tell me that I need: 3 pieces of lumber, 10 nails, and 1 gallon of paint. But, since nails are also a product by itself it would tell me that I need 1lbs of iron.

I see the outline as:

  • Products: Desk
  • Raw Material: Lumber x 3, Paint x 1
  • Required Products: Nails x 10
  • Required Products Raw Material: Iron x 1

What would be the best way to build the array?

There currently isn't any code to share since I'm still planning how, and what, the best approach is to the array, if an array is appropriate at all.

请阅读官方的“ 8.7。数组-有效的数值数组¶” https://docs.python.org/3/library/array.html

Thank you for all your input. I've looked into using a dictionary as suggested by juanpa.arrivillage and hpaulj. Using a python dictionary turned out to be the way to go.

The resources I used for dictionaries is:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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