Posted by: xSicKxBot - 04-11-2020, 12:47 AM - Forum: Lounge
- No Replies
Call Of Duty: Warzone Brings Back Trios
Call of Duty Warzone, the free-to-play battle royale as part of Modern Warfare, got rid of Trios mode when it launched Season 3, introducing Quads instead. That only lasted a couple of days, because Infinity Ward has now added Trios back into the game, alongside Quads so you can take your pick.
Infinity Ward tweeted out the announcement that Trios was back. At first the return of Trios was using older, pre-Season 3 loot pools, but Infinity Ward quickly issued a fix for that as well.
Other recent changes include a price increase for the Loadout Drop to $10,000, marking another price change to the powerful ability following feedback that it was still overpowered. It lets you call in an airdrop that comes with a loadout of weapons, so the ability to pick your weaponry beforehand can be a big advantage. The update also shows a distance counter between yourself and teammates to help squads stick together.
This article shows you how to calculate the average of a given list of numerical inputs in Python.
In case you’ve attended your last statistics course a few years ago, let’s quickly recap the definition of the average: sum over all values and divide them by the number of values.
So, how to calculate the average of a given list in Python?
Python 3.x doesn’t have a built-in method to calculate the average. Instead, simply divide the sum of list values through the number of list elements using the two built-in functions sum() and len(). You calculate the average of a given list in Python as sum(list)/len(list). The return value is of type float.
Here’s a short example that calculates the average income of income data $80000, $90000, and $100000:
income = [80000, 90000, 100000]
average = sum(income) / len(income)
print(average)
# 90000.0
You can see that the return value is of type float, even though the list data is of type integer. The reason is that the default division operator in Python performs floating point arithmetic, even if you divide two integers.
Puzzle: Try to modify the elements in the list income so that the average is 80000.0 instead of 90000.0 in our interactive shell:
If you cannot see the interactive shell, here’s the non-interactive version:
# Define the list data
income = [80000, 90000, 100000] # Calculate the average as the sum divided
# by the length of the list (float division)
average = sum(income) / len(income) # Print the result to the shell
print(average) # Puzzle: modify the income list so that
# the result is 80000.0
This is the absolute minimum you need to know about calculating basic statistics such as the average in Python. But there’s far more to it and studying the other ways and alternatives will actually make you a better coder. So, let’s dive into some related questions and topics you may want to learn!
Python List Average Median
What’s the median of a Python list? Formally, the median is “the value separating the higher half from the lower half of a data sample” (wiki).
How to calculate the median of a Python list?
Sort the list of elements using the sorted() built-in function in Python.
Calculate the index of the middle element (see graphic) by dividing the length of the list by 2 using integer division.
Return the middle element.
Together, you can simply get the median by executing the expression median = sorted(income)[len(income)//2].
Here’s the concrete code example:
income = [80000, 90000, 100000, 88000] average = sum(income) / len(income)
median = sorted(income)[len(income)//2] print(average)
# 89500.0 print(median)
# 90000.0
The mean value is exactly the same as the average value: sum up all values in your sequence and divide by the length of the sequence. You can use either the calculation sum(list) / len(list) or you can import the statistics module and call mean(list).
These are especially interesting if you have two median values and you want to decide which one to take.
Python List Average Standard Deviation
Standard deviation is defined as the deviation of the data values from the average (wiki). It’s used to measure the dispersion of a data set. You can calculate the standard deviation of the values in the list by using the statistics module:
import statistics as s lst = [1, 0, 4, 3]
print(s.stdev(lst))
# 1.8257418583505538
Python List Average Min Max
In contrast to the average, there are Python built-in functions that calculate the minimum and maximum of a given list. The min(list) method calculates the minimum value and the max(list) method calculates the maximum value in a list.
Here’s an example of the minimum, maximum and average computations on a Python list:
import statistics as s lst = [1, 1, 2, 0]
average = sum(lst) / len(lst)
minimum = min(lst)
maximum = max(lst) print(average)
# 1.0 print(minimum)
# 0 print(maximum)
# 2
Python List Average Sum
How to calculate the average using the sum() built-in Python method? Simple, divide the result of the sum(list) function call by the number of elements in the list. This normalizes the result and calculates the average of all elements in a list.
Again, the following example shows how to do this:
import statistics as s lst = [1, 1, 2, 0]
average = sum(lst) / len(lst) print(average)
# 1.0
Python List Average NumPy
Python’s package for data science computation NumPy also has great statistics functionality. You can calculate all basic statistics functions such as average, median, variance, and standard deviation on NumPy arrays. Simply import the NumPy library and use the np.average(a) method to calculate the average value of NumPy array a.
Here’s the code:
import numpy as np a = np.array([1, 2, 3])
print(np.average(a))
# 2.0
Python Average List of (NumPy) Arrays
NumPy’s average function computes the average of all numerical values in a NumPy array. When used without parameters, it simply calculates the numerical average of all values in the array, no matter the array’s dimensionality. For example, the expression np.average([[1,2],[2,3]]) results in the average value (1+2+2+3)/4 = 2.0.
However, what if you want to calculate the weighted average of a NumPy array? In other words, you want to overweight some array values and underweight others.
You can easily accomplish this with NumPy’s average function by passing the weights argument to the NumPy average function.
In the first example, we simply averaged over all array values: (-1+1+2+2)/4 = 1.0. However, in the second example, we overweight the last array element 2—it now carries five times the weight of the other elements resulting in the following computation: (-1+1+2+(2+2+2+2+2))/8 = 1.5.
Let’s explore the different parameters we can pass to np.average(...).
The NumPy array which can be multi-dimensional.
(Optional) The axis along which you want to average. If you don’t specify the argument, the averaging is done over the whole array.
(Optional) The weights of each column of the specified axis. If you don’t specify the argument, the weights are assumed to be homogeneous.
(Optional) The return value of the function. Only if you set this to True, you will get a tuple (average, weights_sum) as a result. This may help you to normalize the output. In most cases, you can skip this argument.
Here is an example how to average along the columns of a 2D NumPy array with specified weights for both rows.
Problem: Given is a list of dictionaries. Your goal is to calculate the average of the values associated to a specific key from all dictionaries.
Example: Consider the following example where you want to get the average value of a list of database entries (e.g., each stored as a dictionary) stored under the key 'age'.
db = [{'username': 'Alice', 'joined': 2020, 'age': 23}, {'username': 'Bob', 'joined': 2018, 'age': 19}, {'username': 'Alice', 'joined': 2020, 'age': 31}] average = # ... Averaging Magic Here ... print(average)
The output should look like this where the average is determined using the ages (23+19+31)/3 = 24.333.
Solution: Solution: You use the feature of generator expression in Python to dynamically create a list of age values. Then, you sum them up and divide them by the number of age values. The result is the average of all age values in the dictionary.
db = [{'username': 'Alice', 'joined': 2020, 'age': 23}, {'username': 'Bob', 'joined': 2018, 'age': 19}, {'username': 'Alice', 'joined': 2020, 'age': 31}] average = sum(d['age'] for d in db) / len(db) print(average)
# 24.333333333333332
Let’s move on to the next question: how to calculate the average of a list of floats?
Python Average List of Floats
Averaging a list of floats is as simple as averaging a list of integers. Just sum them up and divide them by the number of float values. Here’s the code:
Next, I’ll give all three examples in a single code snippet:
lst = [(1, 2), (2, 2), (1, 1)] # 1. Unpacking
lst_2 = [*lst[0], *lst[1], *lst[2]]
print(sum(lst_2) / len(lst_2))
# 1.5 # 2. List comprehension
lst_3 = [x for t in lst for x in t]
print(sum(lst_3) / len(lst_3))
# 1.5 # 3. Nested for loop
lst_4 = []
for t in lst: for x in t: lst_4.append(x)
print(sum(lst_4) / len(lst_4))
# 1.5
Unpacking: The asterisk operator in front of an iterable “unpacks” all values in the iterable into the outer context. You can use it only in a container data structure that’s able to catch the unpacked values.
List comprehension is a compact way of creating lists. The simple formula is [ expression + context ].
Expression: What to do with each list element?
Context: What list elements to select? It consists of an arbitrary number of for and if statements.
The example [x for x in range(3)] creates the list [0, 1, 2].
Python Average Nested List
Problem: How to calculate the average of a nested list?
Example: Given a nested list [[1, 2, 3], [4, 5, 6]]. You want to calculate the average (1+2+3+4+5+6)/6=3.5. How do you do that?
Solution: Again, there are three solution ideas:
Unpack the tuple values into a list and calculate the average of this list.
Next, I’ll give all three examples in a single code snippet:
lst = [[1, 2, 3], [4, 5, 6]] # 1. Unpacking
lst_2 = [*lst[0], *lst[1]]
print(sum(lst_2) / len(lst_2))
# 3.5 # 2. List comprehension
lst_3 = [x for t in lst for x in t]
print(sum(lst_3) / len(lst_3))
# 3.5 # 3. Nested for loop
lst_4 = []
for t in lst: for x in t: lst_4.append(x)
print(sum(lst_4) / len(lst_4))
# 3.5
Unpacking: The asterisk operator in front of an iterable “unpacks” all values in the iterable into the outer context. You can use it only in a container data structure that’s able to catch the unpacked values.
List comprehension is a compact way of creating lists. The simple formula is [ expression + context ].
Expression: What to do with each list element?
Context: What list elements to select? It consists of an arbitrary number of for and if statements.
The example [x for x in range(3)] creates the list [0, 1, 2].
Where to Go From Here
Python 3.x doesn’t have a built-in method to calculate the average. Instead, simply divide the sum of list values through the number of list elements using the two built-in functions sum() and len(). You calculate the average of a given list in Python as sum(list)/len(list). The return value is of type float.
If you keep struggling with those basic Python commands and you feel stuck in your learning progress, I’ve got something for you: Python One-Liners (Amazon Link).
In the book, I’ll give you a thorough overview of critical computer science topics such as machine learning, regular expression, data science, NumPy, and Python basics—all in a single line of Python code!
OFFICIAL BOOK DESCRIPTION:Python One-Liners will show readers how to perform useful tasks with one line of Python code. Following a brief Python refresher, the book covers essential advanced topics like slicing, list comprehension, broadcasting, lambda functions, algorithms, regular expressions, neural networks, logistic regression and more. Each of the 50 book sections introduces a problem to solve, walks the reader through the skills necessary to solve that problem, then provides a concise one-liner Python solution with a detailed explanation.
In the face of the Covid-19 outbreak, several tech companies have stepped up in their attempt to make life a little bit easier, including Pluralsight. Pluralsight are running a promo called Stay Home Skill Up #FreeApril, which makes all 7000+ of their courses available for free. You do not need a credit card to sign up, simply an email address. The free account is valid during the month of April, expiring May 1st.
Click here to sign up. You can learn more about the promotion and Pluralsight in general in the video below.
Right in time for the bank holiday weekend (depending where you are), Niantic is gearing up to drop an exciting new feature in Pokémon Go: online leaderboards. These tie into the Go Battle League feature, and provide you with a list of the top 500 players statistically. The leaderboard hasn’t gone live yet, but you’ll be able to see it at the official Pokémon Go live website as soon as the Go Battle League changes to Master League from Ultra.
The leaderboard will detail the top 500 players’ nicknames, teams, ranks, ratings, and the total number of battles played. This information is taken from the previous day’s statistics, and will update between 20:00 and 22:00 UTC each day. If you want to make it on the leaderboard, you’ll not only have to be a good enough battler, but you’ll also have to ensure that you don’t have an offensive nickname.
To celebrate the launch of the Go Battle League leaderboards, Niantic is hosting a Go Battle Day event on Sunday, which features the Pokémon Marill. The more battles you perform between 11:00 and 14:00 in your local time zone, the higher the chance you’ll have of encountering the fan-favourite Pokémon.
Marill will also appear as a guaranteed reward after your first and third wins, though those who own a premium battle pass will get Marill after every single win. All players will also receive twice the normal amount of stardust for catching Marill.
Niantic is also extending the number of battles you can perform for the entirety of Sunday (in your local time). Rather than the five sets of battles you can typically perform, Niantic is increasing this to 20. That’s a whopping 100 battles for those who want to participate.
If you’re interested, you can go ahead and grab Pokémon Go from the App Store or Google Play right now and get ready for the online leaderboards going live later today. The Go Battle Day event happens on Sunday.
Apple & Google’s contact tracing won’t stop COVID-19, but it will help
Using smartphone contact tracing to track and mitigate the spread of COVID-19 has been floated as a possible way out of the outbreak —but there are plenty of signs suggesting that its effectiveness is an open question.
Smartphone surveillance seems like a promising way to mitigate the COVID-19 pandemic, but there are major hurdles that it may not be able to overcome. Credit: Giles Lambert.
The coronavirus has upended life for most Americans, and government and private entities are looking for a way out. On Friday, Apple and Google announced a joint initiative to develop systems for cross-platform contact tracing. But there’s much more to the conversation, and the probability of the system actually working, than you might see at first glance.
Past attempts at COVID-19 surveillance
A heatmap of smartphones held by Florida beachgoers in March, collected from mobile ad firm X-Mode. Credit: Tectonix
The U.S. government is already using smartphone location data to track the movements of Americans, per a March story from The Wall Street Journal.
According to the report, the lion’s share of that data is sourced from mobile advertising firms, either from location-tracking applications or from app developers who resell the data. Some of it has been provided by Google’s “Community Mobility Reports” project, which is collected on an opt-in basis from Google users.
But neither of those data types actually count as contact tracing. The data, stripped of personally identifiable information, is only really useful for keeping tabs on where people are congregating, and the general patterns of movement of large groups of people. It isn’t useful for tracking out how and when COVID-19 spreads from person-to-person.
More than that, privacy advocates have long cautioned that this type of location data can never be truly anonymized. In 2019, a research paper published by the University of Washington shows that it was relatively trivial to figure out a specific person’s location using location-based ad targeting. On the flip side, unmasking an “anonymous” user is also relatively easy for skilled attackers.
Apple has long been trying to fight against data collection from advertisers and third-party analytics firms. The iOS 13 update, for example, contained new features that Ad Age said “crippled” location-based advertising. Again, that’s the same data type provided to the government by marketing firms.
All of this has largely lead to short-range Bluetooth signals being forwarded as the most realistic means to implement contact tracing on a widespread basis. Hence Apple and Google’s Friday announcement. But while it does away with some of the pitfalls of mass geo-surveillance, it has its own hurdles to overcome.
The Apple and Google solution
Credit: Apple, Google
In a rare show of unity, Apple and Google on Friday announced new plans for a cross-platform, system-level feature that will allow public health officials to track and possibly reduce the spread of COVID-19.
By leveraging short-range Bluetooth signals, the system will help public health officials identify and follow up with smartphone users who have possibly come into contact with someone infected by COVID-19. They’ll even receive a notification on their phone that this event occurred.
Both companies are likely highly conscious of their respective privacy reputations, so they both claim that the system is being developed in a private and transparent manner. Out of the gate, they’ve published documentation illustrating how the system would work, including one document focused on the cryptographic standards used to protect privacy.
Contact tracing can help slow the spread of COVID-19 and can be done without compromising user privacy. We’re working with @sundarpichai & @Google to help health officials harness Bluetooth technology in a way that also respects transparency & consent. https://t.co/94XlbmaGZV
The initiative will apparently be deployed in two parts. In May, both companies will release a developer API for iOS and Android that app makers and public health teams can use in their own apps to enable contact tracing. Deeper system-level functionality, which will presumably negate the need for a third-party app entirely, will be released “in the coming months.”
But while Apple and Google are the most high-profile proponents of Bluetooth contact tracing, they are far from the first to float the idea. Earlier in April, researchers at MIT developed essentially the same system partly inspired by Apple’s offline Find My feature.
Contact tracing apps have also already been used in places like Singapore and South Korea, where they reached varying levels of success.
The problems with Bluetooth contact tracing
An illustration of Bluetooth contact tracing. Credit: MIT
Bluetooth-based contract tracing still has one major downfall. Both Apple and Google made it clear that both waves of contact tracing deployment will be offered on an opt-in basis. The first wave requires that users download an app using the API. The second wave explicitly says users need to “choose to opt in.”
Like social distancing, this type of contact tracing absolutely depends on adoption by a significant portion of the population. Otherwise, it won’t make much of a difference. The fact that this is being deployed on both iOS and Android certainly helps, but it’s not enough to ensure that most people will actually use it, particularly in the U.S.
Unless this type of system is government-mandated, we have serious doubts that enough people are going to volunteer for it to be effective. This is borne out by many states and local governments only starting to ensure compliance with social distancing requirements by force of law when citizens didn’t voluntarily adopt suggestions.
On the flip side, government-mandated contact tracing runs into the same privacy and ethical issues as widespread location surveillance, and will likely meet the same resistance that voluntary lock-in did.
And, there are still some signs casting doubt on whether it really will help curb the spread of COVID-19. Just take a look at Singapore, which implemented fastidious physical contact tracing and surveillance methods, along with an app that used a mix of Bluetooth, Wi-Fi, GPS and cell tower signals to track user locations.
Prime Minister Lee Hsien Loong said that despite the “good contact tracing,” the government has been unable to figure out how people are catching COVID-19 for “nearly half” of cases. While initially a “master class” for COVID-19 mitigation success, the BBCreports that there has since been a surge in new cases on the tiny island-state despite control measures.
Singapore is a small country with a population smaller than New York City. Adopting widespread contact tracing in the U.S. may be near impossible, even with the computing and financial might of Apple and Google behind it. Even though its effectiveness in Singapore is questionable, it probably won’t do nearly as well in larger countries just because of scale.
And, of course, there are unanswered questions about what will happen to all of these systems and data once the shadow of COVID-19 no longer looms over daily life, as digital rights group The Electronic Frontier Foundation points out. Unless the systems are completely dismantled and the data wiped, the possibility for dragnet surveillance is still there.
Possible ways forward
As we’ve thoroughly covered, for a contact tracing app to be effective, it needs to be used by at least a majority of citizens. For that, it either needs the trust of the people or it needs to be mandated.
In the U.S., neither of those options seems particularly promising, with trust in both the federal government and technology juggernauts at a relative low. Even pro-privacy Apple may have a hard time persuading people to willingly undergo surveillance.
Even if a simple majority of people sign up for contact tracing, the system likely won’t do much for most COVID-19 cases, as is evidenced by cases like Singapore and South Korea. If the government starts requiring the usage of the app or implements it was a prerequisite for testing, there will undoubtedly be a backlash.
Which begs the question of what will actually work, a question many officials in the U.S. are actively trying to answer. Without something of a return to normalcy, the economic impact may well be unimaginable. And if we return to normal too quickly, lives will be lost — and the economy will still see a major impact.
One of the possible alternatives, per several proposals seen by Vox, is to implement mass coronavirus testing in lieu of surveillance. Like with mass location tracking or contact tracing, that’s a herculean effort.
The most realistic way forward is a balanced approach mixing these strategies. But that, of course, is easier said than done. The Apple and Google systems will help because they’re privacy-respecting and cross-platform, reducing friction and centralizing data. But it’s just piece of a larger puzzle, and past contract tracing attempts suggest it may not be a significant piece.
Until a vaccine is implemented — something that’s at least a full year away according to experts and the companies developing them — solutions like these are only going to be able to do so much.
Using Fedora to quickly implement REST API with JavaScript
Fedora Workstation uses GNOME Shell by default and this one was mainly written in JavaScript. JavaScript is famous as a language of front-end development but this time we’ll show its usage for back-end.
We’ll implement a new API using the following technologies: JavaScript, Express and Fedora Workstation. A web browser is being used to call the service (eg. Firefox from the default Fedora WS distro).
Installing of necessary packages
Check: What’s already installed?
$ npm -v
$ node -v
You may already have both the necessary packages installed and can skip the next step. If not, install nodejs:
$ sudo dnf install nodejs
A new simple service (low-code style)
Let‘s navigate to our working directory (work) and create a new directory for our new sample back-end app.
$ cd work
$ mkdir newApp
$ cd newApp
$ npx express-generator
The above command generates an application skeleton for us.
$ npm i
The above command installs dependencies. Please mind the security warnings – never use this one for production.
Crack open the routes/users.js
Modify line #6 to:
res.send(data);
Insert this code block below var router:
let data = { '1':'Ann', '2': 'Bruno', '3': 'Celine' }
Save
the modified file.
We modified a route and added a new variable data. This one could be declared as a const as we didn‘t modify it anywhere. The result:
Running the service on your local Fedora workstation machine
$ npm start
Note: The application entry point is bin/www. You may want to change the port number there.
It‘s also possible to leverage the Developer tools. Hit F12 and in the Network tab, select the related GET request and look at the side bar response tab to check the data.
Conclusion
Now we have got a service and and an unnecessary index accessible through localhost:3000. To get quickly rid of this:
Take To The Skies In Hamster’s Latest Arcade Archives Release MX5000
Hamster has added another Arcade Archives game to the Switch eShop. This time around, it’s Konami’s 1987 shoot ’em up, MX5000 (otherwise known as FLAK ATTACK). Like previous releases, this one will set you back $7.99 / £6.29 and supports up to two players.
You’ll take control of “the latest fighter aircraft” of the Roufanis territory as you fight with the Desalis empire, which seeks world domination. Some features include a “military style worldview”, simple controls and exciting BGM. Below are some screens:
The Arcade Archives series has faithfully reproduced many classic arcade masterpieces – allowing players to change various settings such as game difficulty and compete against high scores set by other players from around the world.
Will you be adding this Arcade Archives release to your Switch HOME Menu? Tell us below.
It seems like someone at Nintendo HQ got a little ahead of themselves with regards to a social network post for an upcoming Splatoon 2 update.
A tweet went out today which mentioned a patch containing “minor adjustments to a variety of weapons” for the popular online shooter, but the tweet was deleted not long afterwards, suggesting that it was posted earlier than was planned. Nintendo had previously stated that another update for the game would be coming in April, so it’s not like it’s a surprise – it’s just odd that the post was nuked.
While Splatoon 2 is unlikely to get a massive update again, Nintendo is clearly continuing to tweak the game’s balance to ensure players remain happy – and tinkering with the myriad weapons available is naturally an ongoing process. The most recent update – Version 5.1.0 – arrived in January and was a multiplayer-focused update that changed a bunch of weapons in the game.
Are there any weapons you’d like to see rebalanced in Splatoon 2? Let us know with a comment.
Final Fantasy 7 Remake Chapter 3 Walkthrough: Home Sweet Slum (Spoiler-Free)
Final Fantasy 7 Remake expands on the original game's portion of the story that takes place in Midgar, increasing the scope and adding a whole lot more to FF7's opening hours. If you're going to stop the evil Shinra Corporation and save Midgar slums, you'll need the best weapons, armor, and materia you can get for your team along the way. That's why we've compiled a walkthrough that'll help you find every hidden chest, complete every sidequest, and win ever boss fight.
But the core of the Final Fantasy experience is the story, which is why we've taken pains to keep this walkthrough spoiler-free. We've marked out where you can find everything you need to become as powerful as possible in FF7, while finding every collectible and unlocking every secret.
Things will be pretty straightforward in the early portion of this chapter. Once you get an apartment, go outside and hang a left past Marco's, continuing around the corner. Take the ladder to the roof to find a chest with a phoenix down inside.