会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133794个问题

import pickle

import numpy as np
from sklearn.linear_model import LogisticRegression
X = []
Y = []
genre_list = ['blues', 'classical', 'country', "disco", 'hiphop', 'jazz', 'metal']
for g in genre_list:
    for n in range(100):
        rad = "d:/BaiduNetdiskDownload/trainset/" +g+'.'+str(n).zfill(5)+'.fft'+'.npy'
        fft_features = np.load(rad)
        X.append(fft_features)
        Y.append(genre_list.index(g))
X = np.array(X)
Y = np.array(Y)
model = LogisticRegression()
model.fit(X,Y)

output = open('model.pkl', 'wb')
pickle.dump(model, output)
output.close()




D:\anaconda\envs\TF2.1\python.exe C:/Users/LENOVO/PycharmProjects/ai_tensorflow2.6/music_classify/music_classifier.py
C:\Users\LENOVO\PycharmProjects\ai_tensorflow2.6\music_classify\music_classifier.py:14: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  X = np.array(X)
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\LENOVO\PycharmProjects\ai_tensorflow2.6\music_classify\music_classifier.py", line 17, in <module>
    model.fit(X,Y)
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\linear_model\_logistic.py", line 1508, in fit
    X, y = self._validate_data(
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\base.py", line 581, in _validate_data
    X, y = check_X_y(X, y, **check_params)
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\utils\validation.py", line 964, in check_X_y
    X = check_array(
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\utils\validation.py", line 746, in check_array
    array = np.asarray(array, order=order, dtype=dtype)
  File "D:\anaconda\envs\TF2.1\lib\site-packages\numpy\core\_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.

请老师看看为啥创建模型这里报错了

Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/Softmax回归 12991楼

import pickle

import numpy as np
from sklearn.linear_model import LogisticRegression
X = []
Y = []
genre_list = ['blues', 'classical', 'country', "disco", 'hiphop', 'jazz', 'metal']
for g in genre_list:
    for n in range(100):
        rad = "d:/BaiduNetdiskDownload/trainset/" +g+'.'+str(n).zfill(5)+'.fft'+'.npy'
        fft_features = np.load(rad)
        X.append(fft_features)
        Y.append(genre_list.index(g))
X = np.array(X)
Y = np.array(Y)
model = LogisticRegression()
model.fit(X,Y)

output = open('model.pkl', 'wb')
pickle.dump(model, output)
output.close()



D:\anaconda\envs\TF2.1\python.exe C:/Users/LENOVO/PycharmProjects/ai_tensorflow2.6/sigmoid/asdsada.py
C:\Users\LENOVO\PycharmProjects\ai_tensorflow2.6\sigmoid\asdsada.py:20: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  X = np.array(X)
TypeError: only size-1 arrays can be converted to Python scalars

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\LENOVO\PycharmProjects\ai_tensorflow2.6\sigmoid\asdsada.py", line 25, in <module>
    model.fit(X, y)
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\linear_model\_logistic.py", line 1508, in fit
    X, y = self._validate_data(
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\base.py", line 581, in _validate_data
    X, y = check_X_y(X, y, **check_params)
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\utils\validation.py", line 964, in check_X_y
    X = check_array(
  File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\utils\validation.py", line 746, in check_array
    array = np.asarray(array, order=order, dtype=dtype)
  File "D:\anaconda\envs\TF2.1\lib\site-packages\numpy\core\_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.

进程已结束,退出代码1

请老师帮我看看为啥报错了

Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/Softmax回归 12992楼
JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 12993楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask数据库 12994楼
JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 12995楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 13000楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 13001楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 13002楼
Python 全系列/第十六阶段:Python 爬虫开发/scrapy框架使用(旧) 13003楼
JAVA 全系列/第六阶段:JavaWeb开发/Ajax技术详解(旧) 13004楼

<template>
  <div id="app">
    <hello>
      <template v-slot:header>
        <div>{{msg}}</div>
      </template>
      <template v-slot:body>
        <div>我是内容部分</div>
      </template>
      <template v-slot:footer>
        <div>我是底部</div>
      </template>
      <template v-slot:default="slotProps">
        <h3>{{slotProps.demo}}</h3>
      </template>
    </hello>
    <DyMy />
  </div>
</template>

<script>
import hello from "./components/hello.vue"
import DyMy from "./components/DyMy.vue"
export default {
  name: 'App',
  data(){
    return{
      msg:"我是头部"
    }
  },
  methods:{
  },
  components: {
    hello,
    DyMy,
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
<template>
  <div>
      <h3>我是动态组件</h3>
      <button @click="changeViewHandle">切换视图显示</button>
      <component :is="currentComponent"></component>
  </div>
</template>

<script>
import child1 from "./child1"
import child2 from "./child2"
export default {
    data(){
        return{
            currentComponent:child1
        }
    },
    methods:{
        changeViewHandle(){
            if(this.currentComponent===child1){
                this.currentComponent=child2
            }else{
                this.currentComponent=child1
            }
        }
    },
    components: {
        child1,
        child2,
    },
}
</script>

<style>

</style>

第一段代码是App.vue,第二个是DyMy.vue,视频15分钟的时候,讲动态组件的时候按照视频上写的代码,控制台有警告,为啥与视频一样会有警告呢?

image.png

Python 全系列/第八阶段:Vue框架/vue框架 13005楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637