小编Deb*_*bie的帖子

python + openCV:只有size-1数组可以转换为Python标量

这是我用cv2.getRotationMatrix2D()函数旋转img的代码.

smoothed_angle = 0

img = cv2.imread("/home/hp/self driving car/steering_wheel_image.png")
print(img.shape) #outputs (240, 240, 3)
rows = img.shape[0]
print(rows) #outputs 240
cols = img.shape[1]
print(cols) #outputs 240

M = cv2.getRotationMatrix2D((cols/2,rows/2),-smoothed_angle,1)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-37-55419a87d5b5> in <module>()
     34 #and the predicted angle
     35 smoothed_angle += 0.2 * pow(abs((predicted_angle_degree - smoothed_angle)), 2.0 / 3.0) * (predicted_angle_degree - smoothed_angle) / abs(predicted_angle_degree - smoothed_angle)
---> 36 M = cv2.getRotationMatrix2D((cols/2,rows/2),-smoothed_angle,1)
     37 dst = cv2.warpAffine(img,M,(cols,rows))
     38 #cv2.imshow("steering wheel", dst)

TypeError: only size-1 arrays …
Run Code Online (Sandbox Code Playgroud)

python opencv

5
推荐指数
1
解决办法
2082
查看次数

Android:无法解析:com.android.support:appcompat-v7:28.1.1

错误:同步失败。未解决的Android依赖项。无法解决:com.android.support:appcompat-v7:28.1.1

配置:

 apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.ercess.ercess_app1"
            minSdkVersion 15
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }



    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        implementation 'com.android.support:appcompat-v7:28.1.1'
        implementation 'com.squareup.picasso:picasso:2.71828'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    }
Run Code Online (Sandbox Code Playgroud)

如何解决呢?

android

4
推荐指数
3
解决办法
2万
查看次数

Python + Numpy:TypeError:'int'对象不可调用

我试图通过10倍交叉验证找到加性平滑的最佳平滑参数.我写了以下代码:

alphas = list(np.arange(0.0001, 1.5000, 0.0001))

#empty list that stores cv scores
cv_scores = []

#perform k fold cross validation
for alpha in alphas:
    naive_bayes = MultinomialNB(alpha=alpha)
    scores = cross_val_score(naive_bayes, x_train_counts, y_train, cv=10, scoring='accuracy')
    cv_scores.append(scores.mean())

#changing to misclassification error
MSE = [1 - x for x in cv_scores]  

#determining best alpha
optimal_alpha = alphas[MSE.index(min(MSE))]
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-9d171ddceb31> in <module>()
     18 
     19 #determining best alpha
---> 20 optimal_alpha = alphas[MSE.index(min(MSE))]
     21 print('\nThe optimal value of …
Run Code Online (Sandbox Code Playgroud)

python numpy

4
推荐指数
1
解决办法
686
查看次数

Python:TypeError:'float'对象不可迭代

我正在尝试从 Pandas 数据框中删除停用词。这是我的代码:

import nltk
from nltk.corpus import stopwords
nltk.download('stopwords')

stop_words = stopwords.words('english')
print(stop_words)

data['description'] = data['description'].apply(lambda x: [item for item in x if item not in stop_words])
Run Code Online (Sandbox Code Playgroud)

输出:

['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're", "you've", "you'll", "you'd", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', "she's", 'her', 'hers', 'herself', 'it', "it's", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', "that'll", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', …
Run Code Online (Sandbox Code Playgroud)

python stop-words pandas

3
推荐指数
1
解决办法
9299
查看次数

如何增加 Matplotlib 图的大小?

我用 Matplotlib 制作了一个马赛克图,但是由于大量的数据点,该图被压缩了,单词相互重叠。我想增加情节的大小。我试过:

plt.figure(figsize=()) 
Run Code Online (Sandbox Code Playgroud)

它没有用。

这是我的代码:

from statsmodels.graphics.mosaicplot import mosaic
import matplotlib.pyplot as plt

plt.figure(figsize=(200,10)) #does not work
plt.rcParams['font.size'] = 10.0
mosaic(plants_sub, ['Symbol', 'Family'], gap=0.1);
Run Code Online (Sandbox Code Playgroud)

输出:

在此处输入图片说明

python matplotlib mosaic-plot

2
推荐指数
1
解决办法
3592
查看次数

将 NULL 插入结构数组时“分配给类型时不兼容的类型”

我正在尝试在 C 中实现链接(哈希)。到目前为止我已经编写了以下代码:

\n
#include<stdio.h>\n#include<stdlib.h>\n#define size 10\n\ntypedef struct hashNode\n{\n    int data;\n    struct hashNode *next;\n} node;\n\nint main()\n{\n    node chain[size];\n    \n    for(int i=0; i<=(size-1); i++)\n        chain[i] = NULL;\n    \n    //insert(chain, 10);\n    \n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我收到以下错误:

\n
#include<stdio.h>\n#include<stdlib.h>\n#define size 10\n\ntypedef struct hashNode\n{\n    int data;\n    struct hashNode *next;\n} node;\n\nint main()\n{\n    node chain[size];\n    \n    for(int i=0; i<=(size-1); i++)\n        chain[i] = NULL;\n    \n    //insert(chain, 10);\n    \n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

c data-structures

1
推荐指数
1
解决办法
106
查看次数

Python + 数据框:AttributeError:'float' 对象没有属性 'replace'

我正在尝试编写一个函数来对 Pandas 数据帧的指定列(描述、事件名称)进行一些文本处理。我写了这段代码:

#removal of unreadable chars, unwanted spaces, words of at most length two from 'description' column and lowercase the 'description' column

def data_preprocessing(source):

    return source.replace('[^A-Za-z]',' ')
    #data['description'] = data['description'].str.replace('\W+',' ')
    return source.lower()
    return source.replace("\s\s+" , " ")
    return source.replace('\s+[a-z]{1,2}(?!\S)',' ')
    return source.replace("\s\s+" , " ")

data['description'] = data['description'].apply(lambda row: data_preprocessing(row))
data['event_name'] = data['event_name'].apply(lambda row: data_preprocessing(row))
Run Code Online (Sandbox Code Playgroud)

它给出了以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-94-cb5ec147833f> in <module>()
----> 1 data['description'] = data['description'].apply(lambda row: data_preprocessing(row))
      2 data['event_name'] = data['event_name'].apply(lambda row: …
Run Code Online (Sandbox Code Playgroud)

python text-processing dataframe pandas

0
推荐指数
1
解决办法
9356
查看次数

ValueError:没有足够的值来解包(预期为 2,得到 1),使用 split() 将字符串拆分为两部分不起作用

我有一个字符串:5kg。我需要将数字部分和文本部分分开。所以,在这种情况下,它应该产生两部分:5kg

为此,我写了一段代码:

grocery_uom = '5kg'
unit_weight, uom = grocery_uom.split('[a-zA-Z]+', 1)

print(unit_weight)
Run Code Online (Sandbox Code Playgroud)

收到此错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-66-23a4dd3345a6> in <module>()
      1 grocery_uom = '5kg'
----> 2 unit_weight, uom = grocery_uom.split('[a-zA-Z]+', 1)
      3 #print(unit_weight)
      4 
      5 

ValueError: not enough values to unpack (expected 2, got 1)
    print(uom)
Run Code Online (Sandbox Code Playgroud)

编辑: 我写了这个:

unit_weight, uom  = re.split('[a-zA-Z]+', grocery_uom, 1) 
print(unit_weight)
print('-----')
print(uom)
Run Code Online (Sandbox Code Playgroud)

现在我得到这个输出:

5 
-----
Run Code Online (Sandbox Code Playgroud)

如何将字符串的第二部分存储到 var 中?

Edit1: 我写了这个解决了我的目的(感谢彼得伍德):

unit_weight = re.split('([a-zA-Z]+)', grocery_uom, 1)[0] …
Run Code Online (Sandbox Code Playgroud)

python regex string

0
推荐指数
1
解决办法
1021
查看次数