Python访问数据类型对象

时间:2020-02-06 12:56:53

标签: python object numpy-ndarray

这可能是一个愚蠢的问题。我有一个“ di”类,其中包含一个属性“ train_indices”。如果访问该目录,则会得到以下结果:

flutter build apk --release

如何访问这些值?我想做这样的事情:

Running Gradle task 'assembleRelease'...                                
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':webview_flutter:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     C:\Users\naonv\.gradle\caches\transforms-2\files-2.1\0a271e99b6771ad4a84318244d532fb7\core-1.0.0\res\values\values.xml:57:5-88:25: AAPT: 
error: resource android:attr/fontVariationSettings not found.

     C:\Users\naonv\.gradle\caches\transforms-2\files-2.1\0a271e99b6771ad4a84318244d532fb7\core-1.0.0\res\values\values.xml:57:5-88:25: AAPT: 
error: resource android:attr/ttcIndex not found.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5m 12s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                     315.2s (!)
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
✏️  Creating `android\settings_aar.gradle`...                       178ms
√ `android\settings_aar.gradle` created successfully.
Building plugin webview_flutter...
Running Gradle task 'assembleAarRelease'...                             
Running Gradle task 'assembleAarRelease'... Done                   37.6s
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
WARNING: The option setting 'android.enableR8=true' is experimental and unsupported.
The current default is 'false'
Consider disabling R8 by removing 'android.enableR8=true' from your gradle.properties before publishing your app.


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'webview_flutter'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 36s


The plugin webview_flutter could not be built due to the issue above.

但这不起作用。任何帮助都非常欢迎。

1 个答案:

答案 0 :(得分:0)

非常简单

# lets define your class as below
class d1:
     import numpy as np
     train_indices = np.array({'bike': 0, 'car': 100, 'motorcycle': 2, 'other': 3, 'truck': 4, 'van': 5}, dtype=object)


# now lets declare and call it
x1 = d1()


# lets iterate through array now 
for index, value in np.ndenumerate(x1.train_indices):
    print(index, type(value),value['car'])


# output:
() <class 'dict'> 100

另一个例子:

import numpy as np
train_indices = np.array({'bike': 0, 'car': 100, 'motorcycle': 2, 'other': 3, 'truck': 4, 'van': 5}, dtype=object)

for index, row in np.ndenumerate(train_indices):
    print (index,row)
    for x,y in row.items():
       print(x ," : ",y)

**output:** 
() {'bike': 0, 'car': 100, 'motorcycle': 2, 'other': 3, 'truck': 4, 'van': 5}
bike  :  0
car  :  100
motorcycle  :  2
other  :  3
truck  :  4
van  :  5

对于裁判:https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndenumerate.html#numpy.ndenumerate