在Python中从数组中删除一些元素

时间:2016-08-04 15:00:11

标签: python python-2.7 python-3.x

我还有一个问题,我在Python中有这个数组:

import numpy as np

A = np.zeros((5));
A[0] = 2;
A[1] = 3;
A[2] = 7;
A[3] = 1;
A[4] = 8;

我想要做的是删除A[i] for i from 2 to 4,也就是说我正在寻找这样的命令:

A = np.delete(A, [2:4])但不幸的是它不起作用,因为我在这里看到了文档:http://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html但它对我没有帮助。

感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

如果你想要的是从numpy数组中删除位置,你可以使用:

np.delete(A, slice(2,5))  # note that the interval is inclusive, exclusive [2, 5)

答案 1 :(得分:0)

您需要使用的是<?php session_start(); // always start your session before any other code $host = "localhost"; $user = "root"; $password = ""; mysql_connect($host,$user,$password); mysql_select_db("testdb") or die(mysql_error()); if(isset($_POST["btnSubmit"])) { $num1 = mysql_real_escape_string($_POST["num1"]); $num2 = mysql_real_escape_string($_POST["num2"]); $num3 = mysql_real_escape_string($_POST["num3"]); $num4 = mysql_real_escape_string($_POST["num4"]); // mysql isn't the safest way to put your code out, however if you do, escape it. You may be better off by using prepared statements, but thats up to you, i am just fixing this code mysql_query("insert into table1(num1,num2,num3,num4) values ('$num1','$num2','$num3','$num4')"); } ?> ,但是您需要传递正确的第二个参数,例如:

numpy.delete