Skip to main content

Python, Update the shape of an array with set values at new indexes based on the update of another array's shape

I have a pandas.DataFrame which contains 2 columns, x and y. The record type for each is a numpy.array. I want to update both x and y based on the new positions added in x.

All records in x column are same and look like:

array([14., 16., 18., 20., 22.,
       24., 26., 28., 30., 32.])

A record in y column looks like:

array([18.71003688, 46.34225223, 62.85395246, 54.6278999 , 44.90160129,
       47.15627018, 59.44501392, 49.35773708, 40.35890602, 17.20255624])

The question here is if I were to update the x column with this (Update to x will only be in the beginning or the end):

array([10., 12., 14., 16., 18.,
       20., 22., 24., 26., 28.,
       30., 32., 34., 36., 38.,
       40.])

I want to update the record in y column to have 10.00 in all the new indexes:

array([10.00, 10.00, 18.71, 46.34, 62.85,
       54.62, 44.90, 47.15, 59.44, 49.35,
       40.35, 17.20, 10.00, 10.00, 10.00,
       10.00])

@richardec:

df.head().to_dict():

{'x': {0: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
  1: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
  2: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
  3: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
  4: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.])},
 'y': {0: array([18.61569528, 23.53634178, 58.36532315, 77.54198597, 28.0641304 ,
         65.30746286, 37.23019412, 41.33584277, 32.32958567, 76.2471661 ]),
  1: array([65.00116509, 55.75035838, 24.0169996 , 65.52242193, 18.68593464,
         41.99858577, 41.04883184, 24.28772448, 79.46411667, 58.41317359]),
  2: array([51.01619179, 48.9177941 , 34.77544541, 35.74428367, 39.83933452,
         42.68396121, 33.37758827, 58.15300226, 66.08925208, 21.33814375]),
  3: array([73.17915777, 32.2479716 , 63.22276059, 19.30288733, 37.25751032,
         27.2461532 , 30.30136879, 78.89398042, 16.11675921, 62.49085551]),
  4: array([43.4760009 , 41.53331501, 29.44308989, 23.66155076, 46.83107104,
         79.15013693, 67.77324069, 74.50343753, 48.71949902, 38.86433951])}}


source https://stackoverflow.com/questions/71023732/python-update-the-shape-of-an-array-with-set-values-at-new-indexes-based-on-the

Comments

Popular posts from this blog

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

The number of nodes and edges I calculated manually and by a method provided by networkx library dont match

I am trying to analyse a graph using networkx library in Python. I have implemented a function that returns the nodes and edges of that graph. After that I counted the number of nodes and edges by implementing the len() function for nodes and edges, which gave me 17 for both nodes and edges. However, when I used the method graph.number_of_nodes() of networkx library it gave me 53. My code: import pandas as pd import networkx as nx import matplotlib.pyplot as plt header_list = ["a","b","w"] E =pd.read_csv("aves-barn-swallow-contact-network.edges",sep=" ",header= None,names=header_list) # print(E.head()) # prints first few rows of the csv file G = nx.from_pandas_edgelist(E,"a","b",["w"]) nx.draw(G) plt.show() class GraphAnalyse: #finding nodes and edges def nodeEdge(self,Graph): nodes = Graph.nodes() edges = Graph.edges() ...